【发布时间】:2014-08-29 08:52:51
【问题描述】:
我不明白为什么 rails datetime 不匹配。以下测试失败,因为我的 created_at 日期不一样,但我不知道为什么
测试
it "renders the course as json" do
course = create(:course)
get :index, format: :json
expect(response.body).to eq [course].to_json
end
输出
CoursesController
GET #index - json
renders the #index view (FAILED - 1)
Failures:
1) CoursesController GET #index - json renders the #index view
Failure/Error: expect(response.body).to eq [course].to_json
expected: "[{\"id\":2,\"partner_id\":2,\"name\":\"MyCourse 1\",\"created_at\":\"2014-08-29T10:49:06.205+02:00\",\"updated_at\":\"2014-08-29T10:49:06.205+02:00\",\"status\":\"active\"}]"
got: "[{\"id\":2,\"partner_id\":2,\"name\":\"MyCourse 1\",\"created_at\":\"2014-08-29T10:49:06.000+02:00\",\"updated_at\":\"2014-08-29T10:49:06.000+02:00\",\"status\":\"active\"}]"
(compared using ==)
# ./spec/controllers/courses_controller_spec.rb:59:in `block (3 levels) in <top (required)>'
任何想法都将不胜感激。
谢谢。
【问题讨论】:
标签: ruby-on-rails-4 rspec