Closed luizkowalski closed 7 months ago
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
Not sure if this case is already covered but seems a false positive to me. The following example is called from a shared example.
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.
Thus, no need for an if
and no false positive.
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).