wrz*_*asa 5 rspec mocking match
我正在尝试使用RSpec模拟和should_receive自定义匹配器.我想捕获由should_receive匹配器返回正确值导致的错误,并导致它输出我的自定义失败消息.
怎么做?或许我应该改变我的做法?
答案是:
match do |obj|
# do some setup and mocks here
begin
RSpec::Mocks::verify # run mock verifications
true
rescue RSpec::Mocks::MockExpectationError => e
# here one can use #{e} to construct an error message
false
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
639 次 |
| 最近记录: |