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 an incorrect autocorrect for RSpec/VerifiedDoubleReference when namespaced class #1589

Merged
merged 1 commit into from
Mar 6, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Fix a false positive for `RSpec/PendingWithoutReason` when `skip` is passed a block inside example. ([@ydah], [@pirj])
- Rename `RSpec/PendingBlockInsideExample` cop to `RSpec/SkipBlockInsideExample`. ([@pirj])
- Deprecate `send_pattern`/`block_pattern`/`numblock_pattern` helpers in favour of using node pattern explicitly. ([@pirj], [@ydah])
- Fix an incorrect autocorrect for `RSpec/VerifiedDoubleReference` when namespaced class. ([@ydah])

## 2.18.1 (2023-01-19)

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rspec/verified_double_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def on_send(node)
expression = class_reference.source_range

add_offense(expression, message: message) do |corrector|
violation = class_reference.children.last.to_s
violation = class_reference.source
corrector.replace(expression, correct_style(violation))

opposite_style_detected
Expand All @@ -102,7 +102,7 @@ def correct_style(violation)
if style == :string
"'#{violation}'"
else
violation
violation.gsub(/^['"]|['"]$/, '')
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/rspec/verified_double_reference_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@
expect_offense(<<~RUBY, verified_double: verified_double)
%{verified_double}('ClassName')
_{verified_double} ^^^^^^^^^^^ Use a constant class reference for verified doubles.
%{verified_double}('Foo::Bar::Baz')
_{verified_double} ^^^^^^^^^^^^^^^ Use a constant class reference for verified doubles.
%{verified_double}('::Foo::Bar')
_{verified_double} ^^^^^^^^^^^^ Use a constant class reference for verified doubles.
RUBY

expect_correction(<<~RUBY)
#{verified_double}(ClassName)
#{verified_double}(Foo::Bar::Baz)
#{verified_double}(::Foo::Bar)
RUBY
end

Expand All @@ -52,10 +58,16 @@
expect_offense(<<~RUBY, verified_double: verified_double)
%{verified_double}(ClassName)
_{verified_double} ^^^^^^^^^ Use a string class reference for verified doubles.
%{verified_double}(Foo::Bar::Baz)
_{verified_double} ^^^^^^^^^^^^^ Use a string class reference for verified doubles.
%{verified_double}(::Foo::Bar)
_{verified_double} ^^^^^^^^^^ Use a string class reference for verified doubles.
RUBY

expect_correction(<<~RUBY)
#{verified_double}('ClassName')
#{verified_double}('Foo::Bar::Baz')
#{verified_double}('::Foo::Bar')
RUBY
end

Expand Down