rubocop / rubocop-rspec

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

Add an else condition to correct `StubbedMock` behavior #1994

Closed corsonknowles closed 1 week ago

corsonknowles commented 3 weeks ago

Fix edge case for StubbedMock where it could return a blank suggestion for unhandled Expectation types.

Completes branch coverage for this file.


Before submitting the PR make sure the following are checked:

If you have created a new cop:

If you have modified an existing cop's configuration options:

corsonknowles commented 3 weeks ago

Hmm, I think this spec passes both before and after the change, so there is some issue here:

  it 'flags `are_expected`' do
    expect_offense(<<~RUBY)
      are_expected.to receive(:bar).and_return(:baz)
      ^^^^^^^^^^^^ Prefer `` over `are_expected` when configuring a response.
    RUBY
  end
corsonknowles commented 3 weeks ago

Okay, I pushed up a real change -- now it only flags on the methods it can correct.

Thoughts?

corsonknowles commented 1 week ago

Okay, how's this approach?

pirj commented 1 week ago

Perfect, thank you, @corsonknowles !