Open movermeyer opened 6 months ago
When applying Minitest/AssertMatch (or Minitest/RefuteMatch)'s auto-fix to the following the working code:
Minitest/AssertMatch
Minitest/RefuteMatch
require "minitest/autorun" class AssertMatchTest < Minitest::Test def test_assert_match_autofix hello = "Hello World!" greeting = %r{Hello} assert hello.match?(%r{World}) assert hello.match? greeting end end
It would auto-correct assert hello.match? greeting to assert_match greeting, hello. Indeed, it works correctly for assert hello.match?(%r{World}).
assert hello.match? greeting
assert_match greeting, hello
assert hello.match?(%r{World})
It auto-corrects assert hello.match? greeting to assert_match hello, greeting (note the order of parameters), which causes the test to error:
assert_match hello, greeting
TypeError: no implicit conversion of Regexp into String
since it didn't swap the order of the parameters.
foo_test.rb
ruby foo_test.rb
rubocop -a foo_test.rb
See the test error.
➜ bundle exec rubocop -V 1.64.1 (using Parser 3.3.0.5, rubocop-ast 1.31.2, running on ruby 3.1.4) [arm64-darwin23] - rubocop-minitest 0.35.0 - rubocop-performance 1.21.0
OnlyRegexpLiteral
Regexp
When applying
Minitest/AssertMatch
(orMinitest/RefuteMatch
)'s auto-fix to the following the working code:Expected behavior
It would auto-correct
assert hello.match? greeting
toassert_match greeting, hello
. Indeed, it works correctly forassert hello.match?(%r{World})
.Actual behavior
It auto-corrects
assert hello.match? greeting
toassert_match hello, greeting
(note the order of parameters), which causes the test to error:since it didn't swap the order of the parameters.
Steps to reproduce the problem
foo_test.rb
)ruby foo_test.rb
)rubocop -a foo_test.rb
)ruby foo_test.rb
)See the test error.
RuboCop version