Skip to content

Commit

Permalink
Fix a false positive for RSpec/NoExpectationExample with pending us…
Browse files Browse the repository at this point in the history
…ing `skip` or `pending` inside an example

Fix: #1388
  • Loading branch information
ydah committed Sep 17, 2022
1 parent c14de33 commit 92c95c1
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 92c95c1

Please sign in to comment.