I have failing specs relating to time.
I understand that times are calculated as seconds from epoch, but I would like this spec to pass if the object representations are close enough.
For example:
expect( @model.end_date ).to eq end_date
expected: Wed, 08 Feb 2017 20:13:30 UTC +00:00
got: Wed, 08 Feb 2017 20:13:30 UTC +00:00
Does anyone have any advice on testing time so that a slight offset won't fail the test?
You can use RSpec's built-in be_within
matcher, which can be also be used for floating point numbers and other data types prone to slight discrepancies:
expect(@model.end_date).to be_within(1.second).of(end_date)