-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSpec/RepeatedSubjectCall flags a false positive #1821
Comments
Ha, I just came here to report the same problem. Another example with false positives: expect { subject.method1 }.to raise_error(SomeException)
expect { subject.method2 }.to raise_error(SomeException)
expect { subject.method3 }.to raise_error(SomeException) |
Hello 👋 , I just wanted to add another example which could be worth mentioning: class Something
def work
private_method
end
private
def private_method
# some call that may raise an error
end
end describe Something do
subject { described_class.new }
describe '#work' do
it 'raises' do
allow(subject).to receive(:private_method).and_raise(
StandardError,
'error message',
)
expect { subject.work }.to raise_error(StandardError, 'error message')
end
end
end |
The RSpec/RepeatedSubjectCall is givin false positives on, for example: - spec/models/workflow/step/branch_package_step_spec.rb:597 - spec/models/workflow/step/branch_package_step_spec.rb:608 See rubocop/rubocop-rspec#1821 for the details.
Not sure if this case is already covered but seems a false positive to me. it 'raises an error if country GB' do
if country_id == 'GB'
expect { action }.to raise_error(ArgumentError)
else
expect { action }.not_to raise_error
end
end |
The expectation inside the "else" clause doesn’t match the docstring. It deserves to be extracted to a separate co text or example. |
Hey 👋🏻
I have a test like this:
from what I understand,
subject
is memorized; in this case,described_class.new(url)
but the.call
is not memoized. I know that because this test is currently passing.I don't think this cop should flag such cases (when the subject invokes another method).
The text was updated successfully, but these errors were encountered: