Trouble comparing time with RSpec

后端 未结 7 746
北荒
北荒 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:57

    Because I was comparing hashes, most of these solutions did not work for me so I found the easiest solution was to simply grab the data from the hash I was comparing. Since the updated_at times are not actually useful for me to test this works fine.

    data = { updated_at: Date.new(2019, 1, 1,), some_other_keys: ...}
    
    expect(data).to eq(
      {updated_at: data[:updated_at], some_other_keys: ...}
    )
    

提交回复
热议问题