這是測試代碼:Rspec的預期,得到了相同的,但還沒有經過測試
it "should return the latest test result object for user" do
value = Diagnostics.latest_test_result_object_for("urine color", @user)
expect(value).to eq(@labtestresult3)
end
這是我得到的結果是:
expected: [{"id"=>3, "lab_test_id"=>4, "user_id"=>1, "user_age"=>34, "numeric_value"=>nil, "boolean_value"=>nil, "string_value"=>"pale yellow", "lab_test_reference_label"=>nil, "lab_test_severity_level"=>nil, "lab_test_provider_id"=>1, "lab_test_method_id"=>1, "lab_test_date"=>Tue, 02 Dec 2014 16:03:33 IST +05:30, "created_at"=>Tue, 02 Dec 2014 16:03:33 IST +05:30, "updated_at"=>Tue, 02 Dec 2014 16:03:33 IST +05:30}]
got: [{"id"=>3, "lab_test_id"=>4, "user_id"=>1, "user_age"=>34, "numeric_value"=>nil, "boolean_value"=>nil, "string_value"=>"pale yellow", "lab_test_reference_label"=>nil, "lab_test_severity_level"=>nil, "lab_test_provider_id"=>1, "lab_test_method_id"=>1, "lab_test_date"=>Tue, 02 Dec 2014 16:03:33 IST +05:30, "created_at"=>Tue, 02 Dec 2014 16:03:33 IST +05:30, "updated_at"=>Tue, 02 Dec 2014 16:03:33 IST +05:30}]
(compared using ==)
Diff:
./spec/lib/diagnostics_spec.rb:51:in `block (2 levels) in <top (required)>'
-e:1:in `<main>'
1 example, 1 failure, 0 passed
Finished in 3.854677444 seconds
我不明白是什麼問題。
請幫忙。
我敢打賭上略有不同的日期時間(不顯示毫秒) – apneadiving 2014-12-02 10:39:06
@apneadiving我想你是對的,很奇怪怎麼我現在用的是相同的:你可以在這個簡單的方式與
timecop
解決問題對象在這兩個地方,我沒有創建一個新的,nvm我用這個'expect(group_arr [0] .map(&:to_s))。eq(@ labtestresult3.attributes.map(&:to_s))' – aelor 2014-12-02 10:50:18