开发者

Does rspec have anything more specific than target.should be < 6?

http://cheat.errtheblog.com/s/rspec/ has for inequalities (such as less than or greater than)

开发者_如何学Go
target.should be < 6

Has anything better been created since the cheat sheet was created?


In RSpec's new expectation syntax, you would express it as:

expect(target).to be < 6


This is still the accepted way to handle this test. It's best to use >, <, and == in my opinion for numerical comparisons -- it's clearer.


If you just want to check it in a variable like target then target.should be < 6 is the way to go.

But if you want to check a property in another object, like customer.orders, where orders is a collection of elements, then you could use the have(n).items matcher.

Example:

customer.should have_at_most(6).orders

That is the same expectation than this:

customer.orders.size.should be < 6

But with a cleaner message

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜