Skip to content

Commit

Permalink
Merge pull request #386 from backus/fix/empty-describe-bugs
Browse files Browse the repository at this point in the history
Fix error when handling empty describe
  • Loading branch information
backus authored Mar 25, 2017
2 parents 310af02 + 8d03c6d commit 7daf81e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

* Add `RSpec/DescribeSymbol` cop. ([@tsigo][])
* Fix error when `RSpec/OverwritingSetup` and `RSpec/ScatteredLet` analyzed empty example groups. ([@backus][])

## 1.14.0 (2017-03-24)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/overwriting_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class OverwritingSetup < Cop
PATTERN

def on_block(node)
return unless example_group?(node)
return unless example_group_with_body?(node)

_describe, _args, body = *node

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/scattered_let.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ScatteredLet < Cop
def_node_matcher :let?, '(block (send nil {:let :let!} ...) ...)'

def on_block(node)
return unless example_group?(node)
return unless example_group_with_body?(node)

_describe, _args, body = *node

Expand Down
5 changes: 5 additions & 0 deletions lib/rubocop/rspec/language/node_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ module NodePattern
extend RuboCop::NodePattern::Macros

def_node_matcher :example_group?, ExampleGroups::ALL.block_pattern

def_node_matcher :example_group_with_body?, <<-PATTERN
(block #{ExampleGroups::ALL.send_pattern} args [!nil])
PATTERN

def_node_matcher :example?, Examples::ALL.block_pattern
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/rubocop/cop/rspec/overwriting_setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@
end
RUBY
end

it 'does not encounter an error when handling an empty describe' do
expect { inspect_source(cop, 'RSpec.describe(User) do end', 'a_spec.rb') }
.not_to raise_error
end
end
5 changes: 5 additions & 0 deletions spec/rubocop/cop/rspec/scattered_let_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@
end
RUBY
end

it 'does not encounter an error when handling an empty describe' do
expect { inspect_source(cop, 'RSpec.describe(User) do end', 'a_spec.rb') }
.not_to raise_error
end
end

0 comments on commit 7daf81e

Please sign in to comment.