Today I've been writing some tests for a new rails 3 app, but after
reading the doc from http://rdoc.info/projects/rspec/rspec-expectations,
I still can't understand why the test doesn't work. My setup is:
rvm 0.1.41
ruby 1.9.2dev (2010-07-11 revision 28618) [x86_64-darwin10.4.0] ->
ruby 1.9.2-rc2
rspec 2.0.0.beta.17
rspec-rails 2.0.0.beta.17
devise 1.1.rc2
This is the test for the controller:
require 'spec_helper'
describe PeopleController do
describe "routes" do
it "should route to GET people#new" do
{:get => "/people/new"}.should route_to(:controller =>
"people", :action => "new")
end
end
describe "Methods" do
before :each do
@member = Factory(:member)
sign_in @member
@person = @member.build_person
end
it "should render form for a new person on GET people#new" do
@member.should_receive(:build_person).and_return(@person)
get :new
assigns[:person].should eql(@person)
response.should be_success
response.should render_template("new")
end
end
end
And the controller:
class PeopleController < ApplicationController
before_filter :authenticate_member!
def new
@person = current_member.build_person
end
end
When running the test I get:
.F.................
1) PeopleController Methods should render form for a new person on GET
people#new
Failure/Error: assigns[:person].should eql(@person)
expected #<Person id: nil, first_name: nil, last_name: nil,
gender: nil, university: nil, year: nil, email: nil, phone: nil,
house: nil, user_account_id: 126, user_account_type: "Member",
home_town: nil, bio: nil, current_location: nil, high_school: nil,
undergrad: nil, profession: nil, concentration: nil, created_at: nil,
updated_at: nil>
got #<Person id: nil, first_name: nil, last_name: nil,
gender: nil, university: nil, year: nil, email: nil, phone: nil,
house: nil, user_account_id: 126, user_account_type: "Member",
home_town: nil, bio: nil, current_location: nil, high_school: nil,
undergrad: nil, profession: nil, concentration: nil, created_at: nil,
updated_at: nil>
(compared using eql?)
# ./spec/controllers/people_controller_spec.rb:24:in `block (3
levels) in <top (required)>'
Finished in 2.29 seconds
19 examples, 1 failure
The error with the full backtrace here: http://gist.github.com/479362
Which doesn't seem to make sense. Any ideas?
Thanks.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users