http://cheat.errtheblog.com/s/rspec/ has for inequalities (such as less than or greater than)
target.should be < 6
Has anything better been created since the cheat sheet was created?
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.
In RSpec’s new expectation syntax, you would express it as:
expect(target).to be < 6
If you just want to check it in a variable like
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.
That is the same expectation than this:
customer.orders.size.should be < 6
But with a cleaner message