Skip to content

Commit

Permalink
Fix false positive in cop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Darhazer committed Apr 10, 2018
1 parent f06e22a commit a400b27
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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 false positive in `RSpec/Pending` cop when pending is used as a method name. ([@Darhazer][])

## 1.25.0 (2018-04-07)

* Add `RSpec/SharedExamples` cop to enforce consistent usage of string to titleize shared examples. ([@anthony-robin][])
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/rspec/pending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ class Pending < Cop

def_node_matcher :pending_block?, PENDING_EXAMPLES.send_pattern

def_node_matcher :rspec?, '(send {(const nil? :RSpec) nil?} ...)'

def on_send(node)
return unless pending_block?(node) || skipped_from_metadata?(node)
return unless rspec?(node)

add_offense(node, location: :expression)
end

Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/rspec/pending_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
RUBY
end

it 'flags pending examples when receiver is explicit' do
expect_offense(<<-RUBY)
RSpec.xit 'test' do
^^^^^^^^^^^^^^^^ Pending spec found.
end
RUBY
end

it 'does not flag describe' do
expect_no_offenses(<<-RUBY)
describe 'test' do; end
Expand Down Expand Up @@ -159,4 +167,10 @@
example_group 'test' do; end
RUBY
end

it 'does not flag method called pending' do
expect_no_offenses(<<-RUBY)
subject { Project.pending }
RUBY
end
end

0 comments on commit a400b27

Please sign in to comment.