rubocop / rubocop-rspec

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

RSpec/RepeatedSubjectCall: false positive for subject as a method argument #1870

Closed K-S-A closed 5 months ago

K-S-A commented 5 months ago

Related to https://github.com/rubocop/rubocop-rspec/issues/1821

Example test-case

  it 'does not register an offense when `subject` as an argument' do
    expect_no_offenses(<<~RUBY)
      RSpec.describe Foo do
        it do
          expect { create(:bar, baz: subject) }.to change { A.count }
          expect { create(:bar, subject) }.to not_change { A.count }
        end
      end
    RUBY
  end

Resulted in a RSpec/RepeatedSubjectCall: Calls to subject are memoized, this block is misleading error message.

Expected result: error should not be reported.