We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I often see checks on message expectations like
expect(subject.foo).to raise_error(Error) do |error| expect(error.message).to match(/..../) end
while raise_error offers .with_message
raise_error
.with_message
The text was updated successfully, but these errors were encountered:
I'm not certain why .with_message is specifically needed, as raise_error itself accepts a second argument for message matching:
expect { raise "oops" }.to raise_error(RuntimeError, /op/)
It might be failure messages are slightly different, needs to be checked.
Sorry, something went wrong.
@pirj Both .with_message and raise_error's second argument give exactly same errors, I'm not sure which one to prefer for this cop:
raise_error's second argument
Failures: 1) Errors runs raise_error with block Failure/Error: expect { 1 }.to raise_error(StandardError) do |error| expect(error.message).to eq('foo') end expected StandardError but nothing was raised # ./raise_spec.rb:7:in `block (2 levels) in <top (required)>' 2) Errors runs raise_error.with_message string Failure/Error: expect { 1 }.to raise_error(StandardError).with_message('foo') expected StandardError with "foo" but nothing was raised # ./raise_spec.rb:13:in `block (2 levels) in <top (required)>' 3) Errors runs raise_error.with_message string Failure/Error: expect { 1 }.to raise_error(StandardError).with_message(/foo/) expected StandardError with message matching /foo/ but nothing was raised # ./raise_spec.rb:17:in `block (2 levels) in <top (required)>' 4) Errors runs raise_error & second argument string Failure/Error: expect { 1 }.to raise_error(StandardError, 'foo') expected StandardError with "foo" but nothing was raised # ./raise_spec.rb:21:in `block (2 levels) in <top (required)>' 5) Errors runs raise_error & second argument regex Failure/Error: expect { 1 }.to raise_error(StandardError, /foo/) expected StandardError with message matching /foo/ but nothing was raised # ./raise_spec.rb:25:in `block (2 levels) in <top (required)>'
No branches or pull requests
I often see checks on message expectations like
while
raise_error
offers.with_message
The text was updated successfully, but these errors were encountered: