Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4615

Testing custom exception with a single expect?

$
0
0

I have a function that I want to test raises an exception on an input, but that exception also carries some more information than just a plain message, and I want to test that too. So I did something like this as seen in the rspec documentation:

it 'raises the correct exception' do   expect { my_call }.to raise_error do |error|     expect(error.some_field).to eq('some data')   endend

This works great, however it runs afoul of the RSpec/MultipleExpectations cop:

RSpec/MultipleExpectations: Example has too many expectations [2/1]

From what I can tell it is impossible to use raise_error in block form like this without more than one expect, so what gives? Is there some way to somehow save the raised exception outside the example so I can spec it normally, without doing something horrible involving rescue in the specs? Or should I use a custom raise_custom_error matcher?


Viewing all articles
Browse latest Browse all 4615

Trending Articles