I have a normal Rails project (without Active Record) using CouchDB (couchrest_model) as a document database.
I did setup RSpec and a basic scaffold 'Project'.
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:
(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 s开发者_StackOverflowhouldn't be so different for other ORMs. Am I missing something?
Which is the best way to fix this test?
Try:
assigns(:projects).should == [@project]
精彩评论