Skip to content

Commit

Permalink
Merge pull request #1768 from rubocop/fix1765
Browse files Browse the repository at this point in the history
Fix an error for `RSpec/SharedExamples` when using examples without argument
  • Loading branch information
bquorning authored Jan 5, 2024
2 parents b7d192a + 6081d65 commit 6e19ee6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Fix an error for `RSpec/SharedExamples` when using examples without argument. ([@ydah])

## 2.26.0 (2024-01-04)

- Add new `RSpec/RedundantPredicateMatcher` cop. ([@ydah])
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SharedExamples < Base

def on_send(node)
shared_examples(node) do
ast_node = node.first_argument
next unless (ast_node = node.first_argument)
next unless offense?(ast_node)

checker = new_checker(ast_node)
Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/cop/rspec/shared_examples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,18 @@
end
RUBY
end

context 'when using run_test!' do
before do
other_cops.dig('RSpec', 'Language', 'Includes', 'Examples')
.push('run_test!')
end

it 'does not occur an error' do
expect_no_offenses(<<~RUBY)
run_test!
RUBY
end
end
end
end

0 comments on commit 6e19ee6

Please sign in to comment.