Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable RSpec/LetSetup cop by default #1

Closed
wants to merge 210 commits into from

Conversation

dpisarewski
Copy link

@dpisarewski dpisarewski commented May 31, 2017

See issue rubocop#94

Drenmi and others added 30 commits December 18, 2016 16:41
This change allows removal of the private method `#node_children` as
well as node type checking within loops in `#top_level_nodes` and
`#describe_statement_children` by replacing it with `#each_child_node`.
…evel-describe

Simplify `TopLevelDescribe` using `#each_child_node`
Renames `#to_node_pattern` to `#node_pattern`
Resolves duplicated pattern definitions of the formats

    (block (send _ #{SELECTOR_SET.node_pattern_union}))

and

    (send _ #{SELECTOR_SET.node_pattern_union})
Detect repeated descriptions in example groups
These objects wrap RuboCop::Node objects in order to unify
traversal and also clarify how certain nodes are being accessed.
Extract RuboCop::RSpec::{Example,ExampleGroup}
Fix expect violation to match rubocop's offense highlighting behavior
Previously, MultipleExpectations depended on ConfigurableMax defining
the method `parameter_name`. This method name changed on the most recent
(unreleased) version of rubocop and this broke the cop. Probably safer
for us to rely on the literal until the public API for rubocop is clear
The changes in bd88c07 changes the node pattern for NestedGroups from

    (block (send nil [SELECTORS UNION PATTERN] ...) (args) ...)

to

    (block (send _ [SELECTORS UNION PATTERN] ...) ...)

which led to issue rubocop#270 being reported. While this did introduce a
change in behavior, it helped reveal an inconsistency in the
implementation. With the change mentioned above, the following code
generated an offense when it didn't in 1.8.0

    RSpec.describe Foo do
      context 'bar' do
        it 'baz' do
          expect(foo).to_not be(1)
          expect(foo).not_to be(1)
        end
      end

      describe '#qux' do
        context 'when quuz' do
          it 'zyxxy' do
            pass
          end
        end
      end
    end

the following nearly equivalent code *did* generate an offense in 1.8
though:

    describe Foo do
      context 'bar' do
        it 'baz' do
          expect(foo).to_not be(1)
          expect(foo).not_to be(1)
        end
      end

      describe '#qux' do
        context 'when quuz' do
          it 'zyxxy' do
            pass
          end
        end
      end
    end

The problem was that the previous node pattern would only start
counting nesting at the first bare `describe` or `context` and would
not count `RSpec.describe`. It was also probably much less efficient
since it was searching through all nodes inside every example group
instead of only searching from top level describes.

This change fixes rubocop#270 by starting a search at the top level describe
and properly handle `RSpec.describe` like `describe`.

This change also convinced me that the current default for NestedGroups
is too aggressive. Almost all of the specs that I write use
`RSpec.describe` which means that rubocop-rspec was more lenient for my
tests. The default MaxNesting is now 3 instead of 2.
Fix bad NestedGroups top level describe behavior
Fix broken reference to RuboCop::Node
Show actual/max value in multiple expectations cop
dgollahon and others added 29 commits March 27, 2017 16:10
…o_language

Add subject! to Language module
- Fixes rubocop violations that are now occuring due to the new rubocop
  release and the corresponding change in the community style guide.
…ith-hash

Fix suggestion when the argument is a hash. Fixes rubocop#267
- Fixes rubocop#402
- Previously the #on_block method would correctly flag cases of leading
  `it` and `should` case-insensitively by downcasing the docstring but
  in the autocorrect phase the message casing  was left untouched which
  caused a nil bug for upper cased `Should`s, `IT`s, etc.
- Prevents words starting with `should` from being flagged
  * ex: `it 'shoulders the burden' {}`
- Improves `shouldn't be` handling
  * original docstring: `shouldn't be true`
  * correction before: `does not be true`
  * correction after: `is not true`
- Fixes the pluralizer so that it is not confused by uppercase letters
  * original docstrings: `should WISH ME LUCK`, `should WORRY`
  * corrections before: `WISHs ME LUCK`, `WORRYs`
  * corrections after: `WISHES ME LUCK`, `WORRIES`
- If a whole word being corrected is completely uppercase, the suffix
  appended will also be uppercase. If the word is mixed case, the
  lowercase suffix will be appended.
- Performs general refactoring.enter the commit message for your changes. Lines starting
- Adds pluralization support for words ending in `z`
  * ex: `buzz` -> `buzzes`
Fix IteratedExpectation crashing when there is an assignment in the iteration
 - Drops dependency on concord
 - Drops dependency on anima
 - Drops dependency on adamantium

See also rubocop/rubocop#3905
Rename ExpectViolation to ExpectOffense
I have been reworking this code so that I can upstream it to RuboCop
proper. See rubocop/rubocop#4337

This implementation is much simpler. We simply split out the annotation
lines from the source and initialize an `AnnotatedSource` object. We
can provide an array of offenses to the `AnnotatedSource` instance and
get back a new `AnnotatedSource` instance representing the real
offenses. `AnnotatedSource` instances then generate an annotated source
string (just like what is provided to the matcher) so we can compare the
strings and get a nice RSpec diff in the output if they don't match.

Way simpler AND way nicer to work with thanks to RSpec's diffs.
…tcher

Refactor ExpectOffense implementation
…attributes-defined-statically-on-factories

Forbids dynamic attributes defined statically on factories
The latest cops (from rubocop#413) depend on the new
`Cop.autocorrect_incompatible_with` method so that autocorrect does
not immeditately clash with the `ExtraSpacing` autocorrect and create
an infinite loop.
This cop checks if example group defines `subject` multiple times.

```ruby
describe Foo do
subject(:user) { User.new }
subject(:post) { Post.new }
end

describe Foo do
let(:user) { User.new }
subject(:post) { Post.new }
end
```

The autocorrect behavior for this cop depends on the type of
duplication:

  - If multiple named subjects are defined then this probably indicates
    that the overwritten subjects (all subjects except the last
    definition) are effectively being used to define helpers. In this
    case they are replaced with `let`.

  - If multiple unnamed subjects are defined though then this can *only*
    be dead code and we remove the overwritten subject definitions.

  - If subjects are defined with `subject!` then we don't autocorrect.
    This is enough of an edge case that people can just move this to
    a `before` hook on their own

Closes rubocop#419
@dpisarewski dpisarewski closed this Jun 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.