CircleCI: bug with specification including timestamps

I have a specification for a method that returns the timestamp of an ActiveRecord object.

The spectrum runs locally, but whenever it runs in CircleCI, there is a slight discrepancy between the expected and the actual.

The specification looks something like this:

describe '#my_method' do it 'returns created_at' do object = FactoryGirl.create(:something) expect(foo.bar(object)).to eq object.created_at end end 

While it runs locally, at CircleCI I constantly get similar error messages.

Here are some examples:

(one)

 expected: 2015-05-09 10:42:59.752192641 +0000 got: 2015-05-09 10:42:59.752192000 +0000 

(2)

 expected: 2015-05-08 10:16:36.777541226 +0000 got: 2015-05-08 10:16:36.777541000 +0000 

Due to an error, I suspect that CircleCI rounds the timestamp value, but I don't have enough information. Any suggestions?

+7
ruby-on-rails rspec circleci
source share
1 answer

I am facing the same problem and currently have an open ticket with CircleCI to get more information. I will update this answer when I learn more.

At the same time, a workaround for passing these tests is to ensure that the timestamp that you work with in a test like this is rounded up using a library that timecop from time to time (e.g. timecop ).

 describe '#my_method' do it 'returns created_at' do # CircleCI seems to round milliseconds, which can result in # slight differences when serializing times. # To work around this, ensure the millseconds end in 000. Timecop.freeze(Time.local(2015)) do object = FactoryGirl.create(:something) expect(foo.bar(object)).to eq object.created_at end end end 

UPDATE:. Based on the initial answer from CircleCI, the above approach is actually their recommended approach. They have not yet been able to explain to me why rounding is actually happening.

UPDATE 2: This seems to be due to a difference in accuracy between different systems. I personally see this problem on OS X. Here's the answer from Circle:

From what I know, Time.now actually has different accuracy in OS X and Linux. I would suggest that you get the same result on other Linux hosts, but all OS X hosts will give you the result without rounding. Maybe I'm wrong, but I remember talking about it with another client. Remember that on a VM or EC2 instance running Linux?

In the "Time" link, you can search for accuracy on the page. The round method can actually adjust the accuracy for you. Would it be an option for you to round out the time in the statement in the test?

I have not tried to confirm my suggestions, but this seems to give an explanation, as well as an additional workaround (rounding the statement in the test), which does not require timecop .

+4
source share

All Articles