How to deal with RSpec time precision error
Public
09 Jul 12:35

In some cases, Ruby uses higher precision to represent time than the DB. When we compare a timestamp before and after saving to the DB it might not be equal.

The easiest solution is to use be_within().of matcher.

time = Time.now

model = SomeModel.create(started_at: time)

expect(model.started_at).to be_within(0.001.seconds).of(time)

Comments

Empty! You must sign in to add comments.