Skip to content

Commit

Permalink
Merge pull request #1389 from ydah/fix/1388
Browse files Browse the repository at this point in the history
Fix a false positive for `RSpec/NoExpectationExample` with pending using `skip` or `pending` inside an example
  • Loading branch information
Darhazer authored Sep 21, 2022
2 parents c14de33 + 92c95c1 commit 3e05139
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 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)

* Fix an error for `RSpec/Capybara/SpecificFinders` with no parentheses. ([@ydah][])
* Fix a false positive for `RSpec/NoExpectationExample` with pending using `skip` or `pending` inside an example. ([@ydah][])

## 2.13.1 (2022-09-12)

Expand Down
8 changes: 8 additions & 0 deletions lib/rubocop/cop/rspec/no_expectation_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ class NoExpectationExample < Base
send_pattern('#Expectations.all')
)

# @!method including_any_skip_example?(node)
# @param [RuboCop::AST::Node] node
# @return [Boolean]
def_node_search :including_any_skip_example?, <<~PATTERN
(send nil? {:pending :skip} ...)
PATTERN

# @param [RuboCop::AST::BlockNode] node
def on_block(node)
return unless regular_or_focused_example?(node)
return if including_any_expectation?(node)
return if including_any_skip_example?(node)

add_offense(node)
end
Expand Down
22 changes: 22 additions & 0 deletions spec/rubocop/cop/rspec/no_expectation_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@
end
end

context 'with no expectation pending example when using `pending` ' \
'inside an example' do
it 'registers no offenses' do
expect_no_offenses(<<~RUBY)
it "is implemented but waiting" do
pending "something else getting finished"
end
RUBY
end
end

context 'with no expectation skipped example when using `skip` ' \
'inside an example' do
it 'registers no offenses' do
expect_no_offenses(<<~RUBY)
it "is skipped" do
skip
end
RUBY
end
end

context 'when Ruby 2.7', :ruby27 do
context 'with no expectation example with it' do
it 'registers an offense' do
Expand Down

0 comments on commit 3e05139

Please sign in to comment.