2012-11-12 37 views
5

我想在自定義匹配器中使用RSpec mock和should_receive。我想捕獲由should_receive引起的錯誤,從匹配器返回適當的值,並導致它輸出我的自定義失敗消息。rspec mock should_receive在自定義匹配器中

怎麼辦?或者,也許我應該改變我的方法?

回答

9

答案是:

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 

終於找到了here

+0

這個超級真棒很有幫助。乾杯。 – thomasfedb