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 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.
- Loading branch information