Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Polishing Ruby on Rails Static Pages in Rails Creating a Pages Controller

Getting multiple failures in tests & on the server [edited]

Hi all,

I've picked up this course having done the ODOT course before. I've downloaded the files from the video page and, after A LOT of messing about (creating secrets and migrating the database etc), have managed to get somewhere near a working app.

The tests are failing, though and I suspect it may be a version issue with Rails or Ruby.

I am getting the same error across multiple tests so I have just been focussing on one test file at the moment to see if I can work out what's wrong. I can't, so here I am!

The error says:

Failure/Error before { sign_in user, password: 'treehouse1' } ActionView::Template::Error: undefined method 'name' for nil:NilClass

So, something's coming back as a nil, not sure what. There's no method called name in my code. The code it references:

before { sign_in user, password: 'treehouse1' }

is a line in the test code - it simulates a user signing in. It is a method that's defined in authentication_helpers.rb as:

module Feature
  def sign_in(user, options={})
    visit "/login"
    fill_in "Email", with: user.email
    fill_in "Password", with: options[:password]
    click_button "Sign In"
  end
end

That all looks OK (it should be, I didn't write it!) and there's still no name method.

I'm not sure how to approach solving this - I've had a Google about it but got nowhere with that. I'm not even sure what to search for!! I'm wondering if the before syntax is now deprecated or replaced but I've no basis for saying that.

Running the server gives the same error undefined method 'name' for nil:NilClass when visiting localhost:3000/todo_lists. That error is at line 3 of index.html.erb which is calling the size method on @todo_list. I suspect that the @todo_list is empty. I added a todo list in the app but this makes no difference - the variable holds nil. Shouldn't @todo_lists be globally accessible? I can sign up and sign in, so there's a valid user there, but on trying to display the list of todo_lists, the code fails due to something being nil which I think is the @todo_lists variable - where should that be instantiated?

Any help would be greatly appreciated.

Thanks in advance,

Steve.

1 Answer

After much messing about I got this figured out.

The code I downloaded was calling the .size method on @todo_lists. I changed this to the .count method and the error went away. I'm sure this will cause problems in the future but, for now, I am up and running!

There were multiple instances of this across the app and changing them has cleared all the errors across the 149 test suite.