rubocop / rubocop-rspec

Code style checking for RSpec files.
https://docs.rubocop.org/rubocop-rspec
MIT License
794 stars 272 forks source link

`RSpec/ExpectActual` autocorrects unsafely given a hash and a matcher without brackets #1834

Closed boardfish closed 3 months ago

boardfish commented 4 months ago

Given this input, for example:

expect({ a: 1 }).to eq something_else

RSpec/ExpectActual autocorrects to this:

expect(something_else).to eq { a: 1 }

This isn't interpreted correctly by Ruby, which returns:

syntax error, unexpected ':', expecting '}' (SyntaxError)

Safe output for this cop would be:

expect(something_else).to eq({ a: 1 })