I'm on section 10.3.1 "User Index" of Ruby on Rails 3 Tutorial. I have one test that refuses to pass and I have researched the error extensively and can't seem to get it to pass.
Here is the error:
1) UsersController GET 'index' for signed-in users should have an element for each user
Failure/Error: response.should have_selector("li", :content => user.name)
NoMethodError:
undefined method name' for nil:NilClass
# ./spec/controllers/users_controller_spec.rb:39:in
block (5 levels) in '
# ./spec/controllers/users_controller_spec.rb:38:in each'
# ./spec/controllers/users_controller_spec.rb:38:in
block (4 levels) in '
I have tried a test to ensure that the user is returning an object instead of an array...it is. I have checked my sign_in and test_sign_in methods. I can probably move on, but fails tests drive me crazy.
Here is my users_controller_spec.rb code: describe "for signed-in users" do
before(:each) do
@user = test_sign_in(Factory(:user))
second = Factory(:user, :name => "Bob", :email => "[email protected]")
third = Factory(:user, :name => "Ben", :email => "[email protected]")
@users = [@users, second, third]
end
it "should be successful" do
get :index
response.should be_success
end
it "should have the right title" do
get :index
response.should have_selector("title", :content => "All users")
end
it "should have an element for each user" do
get :index
@users.each do |user|
response.should have_selector("li", :content => user.name)
end
end
end
end
Please help!!!