Rspec raise_error error, even if the method raises an error

My test is as follows:

it 'does return an error when passing a non-subscription or trial membership' do expect(helper.description_for_subscription(recurring_plan)).to raise_error(RuntimeError) end

My method returns this:

fail 'Unknown subscription model type!'

However, Rspec returns with this error message:

Failure/Error: expect(helper.description_for_subscription(recurring_plan)).to raise_error(RuntimeError) RuntimeError: Unknown subscription model type!

What's happening?

+5
source share
1 answer

You should wrap the wait in a block using {} instead of () :

 expect{ helper.description_for_subscription(recurring_plan) }.to raise_error(RuntimeError) 

Check the Pending Errors section here.

+6
source

Source: https://habr.com/ru/post/1233438/


All Articles