0
votes

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:inblock (5 levels) in ' # ./spec/controllers/users_controller_spec.rb:38:in each' # ./spec/controllers/users_controller_spec.rb:38:inblock (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!!!

1
I actually just solved this. In my code for @ users = [@user, second, third] I misspelled @user with @ users.Mark O'Donnell
You should write it as an answer, and accept it. This way the question will be marked as "answered", like it should.janko-m

1 Answers

1
votes

I actually just solved this. In my code for @ users = [@user, second, third] I misspelled @user with @ users