开发者

Can rspec output the value that made a test fail?

I have statements like:

@obj[:attribute].eql?("TestValue").should be_true

And it would be nice if instead of just telling me that the test failed, it told me that it failed because @obj[:attribute] was nil or was 1234 or whatever it 开发者_Go百科was. Is there any way to do this?


When doing something like

@obj.attribute.should eql(5)

and it throws an error, you'll usually see

expected 5
     got 10

Is there a specific reason why you are doing eql??


Sure, rspec does output the difference between expected and actual values. You just need to change your matcher to provide more relevant information to you. Right now your expectation is that the expression @obj[:attribute].eql?("TestValue") will be true and rspec will inform you that it was false instead. If you rewrite your expectation as

@obj[:attribute].should eql("TestValue")

You should see the sort of output you are looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜