我的测试看起来像这样:
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
我的方法返回:
fail 'Unknown subscription model type!'
然而Rspec带着这条失败的消息回来了:
Failure/Error: expect(helper.description_for_subscription(recurring_plan)).to raise_error(RuntimeError)
RuntimeError:
Unknown subscription model type!
发生了什么事?
答案 0 :(得分:6)
您应该使用{}
而不是()
将期望包装在一个块中:
expect{
helper.description_for_subscription(recurring_plan)
}.to raise_error(RuntimeError)
检查预期错误部分here