这是我的代码:
account_double.should_receive(:withdraw).and_raise
Run Code Online (Sandbox Code Playgroud)
我得到输出:
1) Statement uses the customer's name in the header
Failure/Error: Unable to find matching line from backtrace
Exception
# ./spec/codebreaker/test.rb:8:in `generate'
# ./spec/codebreaker/test.rb:20
# /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `inject'
Run Code Online (Sandbox Code Playgroud)
它找不到异常.我怎么能通过这个测试?
我不明白这张照片
尝试添加一个参数and_raise- Exception要传递给的类或字符串RuntimeError
来自文档:
告诉mock引发异常而不是返回值.可以是任何Exception类,任何Exception类的实例,或String(在这种情况下,将使用该String作为其消息引发RuntimeError).
account_double.should_receive(:withdraw).and_raise(Exception)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5578 次 |
| 最近记录: |