Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CircleCI: error with a spec involving timestamps

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

The spec passes locally, but whenever it is run on CircleCI, there is a slight mismatch between the expected and the actual.

The spec 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 passes locally, on CircleCI, I continually get similar error messages.

Here are examples:

(1)

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

From the error, I suspect that CircleCI is rounding up the timestamp value, but I do not have enough information. Any suggestions?

like image 532
Sung Cho Avatar asked May 09 '15 10:05

Sung Cho


1 Answers

You can also define the precision of your time columns in your schema, this way ActiveRecord will take care of precision truncating at type cast.

See https://github.com/rails/rails/blob/39de1156970d52b441ff944862ebe16a47de784f/activemodel/lib/active_model/type/date_time.rb#L18

like image 85
j15e Avatar answered Nov 16 '22 01:11

j15e