【发布时间】:2018-11-28 09:11:33
【问题描述】:
为了与我们在规范中使用的 hashdata 进行比较
it 'should return the rec_1 in page format' do
expect(response_body_json).to eql(Preseneter.new(ActiveRecordObject).page)
end
Presenter 是一个类,它将接受 ActiveRecordObject 并以特定格式的哈希数据进行响应。
然后我们将带有时间戳的 updated_at 添加到 hash_data。
在我的代码中我有updated_at = Time.zone.now
所以规范开始失败,因为两个 updated_at 有几秒钟的差异。
尝试存根 Time.zone
it 'should return the rec_1 in page format' do
allow(Time.zone).to receive(:now).and_return('hello')
expect(response_body_json).to eql(Preseneter.new(ActiveRecordObject).page)
end
但现在 response_body_json.updated_at 以“你好”的形式出现 但右手边仍然带有时间戳
我哪里错了??? 还是有其他更好的方法来处理这种情况?
【问题讨论】:
标签: ruby-on-rails ruby rspec rspec-rails