Dan Barbarito
Dan Barbarito

Reputation: 480

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??

Upvotes: 8

Views: 2520

Answers (1)

AbM
AbM

Reputation: 7779

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

Upvotes: 9

Related Questions