我有一个使用 CouchDB (couchrest_model) 作为文档数据库的普通 Rails 项目(没有 Active Record)。
我确实设置了 RSpec 和一个基本的脚手架“项目”。
当我测试以下规格时:
before(:each) do
@project = Project.create! valid_attributes
end
describe "GET index" do
it "assigns all projects as @projects" do
get :index
assigns(:projects).should eq([@project])
end
end
我收到以下错误:
Failure/Error: assigns(:projects).should eq([@project])
expected [{"name"=>"test",
"updated_at"=>2011-05-28 11:24:04 -0500,
"created_at"=>2011-05-28 11:24:04 -0500,
"couchrest-type"=>"Project",
"_id"=>"709edbfaafb24fa1eff7d5f3966b2bda",
"_rev"=>"1-ae3f6356f8e32f6006337a4f3759bca4"}]
got [{"name"=>"test",
"updated_at"=>2011-05-28 11:24:04 -0500,
"created_at"=>2011-05-28 11:24:04 -0500,
"_id"=>"709edbfaafb24fa1eff7d5f3966b2bda",
"_rev"=>"1-ae3f6356f8e32f6006337a4f3759bca4",
"couchrest-type"=>"Project"}]
似乎唯一的区别是哈希中元素的顺序:
(compared using ==)
Diff:
@@ -1,7 +1,7 @@
[{"name"=>"test",
"updated_at"=>2011-05-28 11:24:04 -0500,
"created_at"=>2011-05-28 11:24:04 -0500,
- "couchrest-type"=>"Project",
"_id"=>"709edbfaafb24fa1eff7d5f3966b2bda",
- "_rev"=>"1-ae3f6356f8e32f6006337a4f3759bca4"}]
+ "_rev"=>"1-ae3f6356f8e32f6006337a4f3759bca4",
+ "couchrest-type"=>"Project"}]
我知道 'rspec' 和 'rspec-rails' 只适用于 Active Record,但对于其他 ORM 来说应该没有太大的不同。我错过了什么吗?
修复此测试的最佳方法是什么?