我使用CouchDB(couchrest_model)作为文档数据库,有一个普通的Rails项目(没有Active Record)。
我确实设置了RSpec和一个基本的脚手架'Project'。
当我测试以下规范时:
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来说它不应该如此不同。我错过了什么吗?
哪种方法可以解决此问题?
答案 0 :(得分:0)
尝试:
assigns(:projects).should == [@project]