[英]Testing errors in Rails with CouchRest Model using RSpec
I have a normal Rails project (without Active Record) using CouchDB (couchrest_model) as a document database.我有一个使用 CouchDB (couchrest_model) 作为文档数据库的普通 Rails 项目(没有 Active Record)。
I did setup RSpec and a basic scaffold 'Project'.我确实设置了 RSpec 和一个基本的脚手架“项目”。
When I test the following spec:当我测试以下规格时:
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
I get the following error:我收到以下错误:
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"}]
It seems that the only difference is the order of the elements in the hash:似乎唯一的区别是 hash 中元素的顺序:
(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"}]
I know 'rspec' and 'rspec-rails' only work out of the box for Active Record, but it shouldn't be so different for other ORMs.我知道 'rspec' 和 'rspec-rails' 只适用于 Active Record,但对于其他 ORM 来说应该没有太大的不同。 Am I missing something?
我错过了什么吗?
Which is the best way to fix this test?修复此测试的最佳方法是什么?
Try:尝试:
assigns(:projects).should == [@project]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.