Skip to content

Commit

Permalink
Merge pull request #1541 from ydah/fix/1540
Browse files Browse the repository at this point in the history
Fix a false negative for `RSpec/Pending` and false positive for `RSpec/NoExpectationExample` when using skipped in metadata is multiline string
  • Loading branch information
Darhazer authored Jan 13, 2023
2 parents b794fba + 769051d commit e9e08dd
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 @@ -10,6 +10,8 @@
- 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 positive for `RSpec/StubbedMock` when stubbed message expectation with a block and block parameter. ([@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 e9e08dd

Please sign in to comment.