Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec raise_error test failing even though the method raises an error

My test looks like this:

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!'

Yet Rspec comes back with this failure message:

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

What is going on??

like image 206
Dan Barbarito Avatar asked Oct 10 '15 22:10

Dan Barbarito


1 Answers

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

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

Check the Expecting Errors section here

like image 63
AbM Avatar answered Nov 14 '22 21:11

AbM