ruby 即使方法引发错误,Rspec raise_error测试也失败

ulmd4ohb  于 9个月前  发布在  Ruby
关注(0)|答案(1)|浏览(91)

我的测试看起来像这样:
第一个月
我的方法返回如下:
fail 'Unknown subscription model type!'
然而,Rspec返回了这个失败消息:
Failure/Error: expect(helper.description_for_subscription(recurring_plan)).to raise_error(RuntimeError) RuntimeError: Unknown subscription model type!
“怎么了?

sqyvllje

sqyvllje1#

你应该将期望值 Package 在一个块中,使用{}而不是()

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

字符串
检查预期错误部分here

相关问题