Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a false negative for RSpec/Pending and false positive for RSpec/NoExpectationExample when using skipped in metadata is multiline string #1541

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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])
Comment on lines +11 to +12
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[memo] CHANGELOGs are separated for easy reading. Please let us know if it would be better to integrate.


## 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