Trouble comparing time with RSpec

后端 未结 7 749
北荒
北荒 2020-12-12 15:23

I am using Ruby on Rails 4 and the rspec-rails gem 2.14. For a my object I would like to compare the current time with the updated_at object attribute after a c

7条回答
  •  无人及你
    2020-12-12 15:56

    You can convert the date/datetime/time object to a string as it's stored in the database with to_s(:db).

    expect(@article.updated_at.to_s(:db)).to eq '2015-01-01 00:00:00'
    expect(@article.updated_at.to_s(:db)).to eq Time.current.to_s(:db)
    

提交回复
热议问题