Skip to content

Commit

Permalink
Merge pull request #1589 from ydah/ydah/fix-1588
Browse files Browse the repository at this point in the history
Fix an incorrect autocorrect for `RSpec/VerifiedDoubleReference` when namespaced class
  • Loading branch information
pirj authored Mar 6, 2023
2 parents d114b99 + aa125ef commit b4c2ae0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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

0 comments on commit b4c2ae0

Please sign in to comment.