In RSpec - how can I test if one attribute is less (or more) than another

It is generally recommended to use expect, not should.

For instance:

  expect(@car.date_from).to be <= @car.date_till

Resources: - BetterSpecs examples - Rspec Docs


Just use <=

date_from.should be <= date_till

@car = Car.create \
  name:      'Buggy',
  date_from: Date.today + 1.day,
  date_till: Date.today + 2.day

expect(@car.date_from).to be <= @car.date_till

More details: RSpec Comparison matchers