Skip to content

Commit

Permalink
Fix a false negative for RSpec/Pending and false positive for `RSpe…
Browse files Browse the repository at this point in the history
…c/NoExpectationExample` when using skipped in metadata is multiline string

Fix: #1540
  • Loading branch information
ydah committed Jan 7, 2023
1 parent c430668 commit 16d6194
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Add new `RSpec/Rails/MinitestAssertions` cop. ([@ydah])
- Fix a false positive for `RSpec/PendingWithoutReason` when not inside example. ([@ydah])
- Fix a false negative for `RSpec/PredicateMatcher` when using `include` and `respond_to`. ([@ydah])
- Fix a false negative for `RSpec/Pending` when using skipped in metadata is multiline string. ([@ydah])
- Fix a false positive for `RSpec/NoExpectationExample` when using skipped in metadata is multiline string. ([@ydah])

## 2.16.0 (2022-12-13)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/mixin/skip_or_pending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module SkipOrPending
def_node_matcher :skipped_in_metadata?, <<-PATTERN
{
(send _ _ <#skip_or_pending? ...>)
(send _ _ ... (hash <(pair #skip_or_pending? { true str }) ...>))
(send _ _ ... (hash <(pair #skip_or_pending? { true str dstr }) ...>))
}
PATTERN

Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/rspec/no_expectation_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,26 @@
it 'is skipped', skip: true do
foo
end
it 'is skipped', skip: "test" do
foo
end
it 'is skipped', skip: "test" \\
"foo" do
foo
end
it 'is pending', :pending do
foo
end
it 'is pending', pending: true do
foo
end
it 'is pending', pending: "test" do
foo
end
it 'is pending', pending: "test" \\
"foo" do
foo
end
RUBY
end

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

it 'flags blocks with pending: string metadata and line break by `\`' do
expect_offense(<<-'RUBY')
it "test", pending: 'test' \
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Pending spec found.
'foo' do
end
RUBY
end

it 'flags blocks with pending: string metadata and line break by `,`' do
expect_offense(<<-RUBY)
it "test", pending: 'test ,
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Pending spec found.
foo' do
end
RUBY
end

it 'flags blocks with pending: surrounded by `%()` stringg metadata ' \
'and line break' do
expect_offense(<<-RUBY)
it "test", pending: %(test ,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Pending spec found.
foo) do
end
RUBY
end

it 'flags blocks with skip: true metadata' do
expect_offense(<<-RUBY)
it 'test', skip: true do
Expand Down

0 comments on commit 16d6194

Please sign in to comment.