Search code examples
ruby-on-railsruby-on-rails-4rspecrspec2rspec-rails

Error when comparing dates in spec


Faced with such an error, how can it be solved?

Failure/Error: specify{ subject[:ends_at].should eq challenge.ends_at.as_json }

   expected: "2014-08-29T08:20:47.019-05:00"
        got: "2014-08-29T08:20:47.000-05:00"

Solution

  • Compare without milliseconds or try freeze time https://github.com/travisjeffery/timecop