-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bad NestedGroups top level describe behavior
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 #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 #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.
- Loading branch information
Showing
6 changed files
with
27 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
require: rubocop-rspec | ||
|
||
inherit_from: .rubocop_todo.yml | ||
|
||
AllCops: | ||
DisplayCopNames: true | ||
TargetRubyVersion: 2.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require: rubocop-rspec | ||
|
||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2017-01-02 14:45:11 -0800 using RuboCop version 0.44.1. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 2 | ||
# Configuration parameters: MaxNesting. | ||
RSpec/NestedGroups: | ||
Exclude: | ||
- 'spec/project/changelog_spec.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters