I am a Ruby/Rails newby, currently reading "Simply Rails 2" by Patrick
Lenz. I am up to the section on functional testing (of the
The first functional test tests the index action of the controller.
Unlike the book however, my functional test fails, a partial listing
of the output is shown below:
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/
Finished in 0.163936 seconds.
ActionView::TemplateError: You have a nil object when you didn't
The error occurred while evaluating nil.name
On line #4 of stories/index.html.erb
1: <p>The time is: <%= @current_time %></p>
3: A random link:
4: <%= link_to(@story.name, @story.link) %>
It seems @story is pointing to a nil object rather than a Story
object. The index action works fine when I manually try it in my
browser so I am thinking it could be that Rails is not finding any
data in the database when it runs this test. I assume the database in
this case is the test database. Querying the Stories table in the
test database AFTER running this test returns no rows.
Below is the test method which is failing:
class StoriesControllerTest < ActionController::TestCase