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 Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Adding Validations to Todo Items

Robert Cooper
Robert Cooper
22,704 Points

Failure of index.html.erb_spec

After running bin/rake I've encountered a failure described as follows

1)  todo_lists/index renders a list of todo_lists
     Failure/Error: assert_select "tr>td", :text => "MyText".to_s, :count => 2
     Minitest::Assertion:
       <MyText> expected but was
       <Title>..
       Expected: 2
         Actual: 0
     # ./spec/views/todo_lists/index.html.erb_spec.rb:21:in `block (2 levels) in <top (required)>'

Here is a sample of my index.html.erb_spec.rb

describe "todo_lists/index" do
  before(:each) do
    assign(:todo_lists, [
      stub_model(TodoList,
        :title => "Title",
        :description => "MyText"
      ),
      stub_model(TodoList,
        :title => "Title",
        :description => "MyText"
      )
    ])
  end

  it "renders a list of todo_lists" do
    render
    # Run the generator again with the --webrat flag if you want to use webrat matchers
    assert_select "tr>td", :text => "Title".to_s, :count => 2
    assert_select "tr>td", :text => "MyText".to_s, :count => 2
  end
end

Here is a sample of the code in my index.html.erb

  <tbody>
    <% @todo_lists.each do |todo_list| %>
      <tr id="<%= dom_id(todo_list) %>">
        <td><%= todo_list.title %></td>
        <td>
          <%= link_to "List Items", todo_list_todo_items_path(todo_list) %>
          <%= todo_list.description %>
          <%= link_to 'Show', todo_list %>
          <%= link_to 'Edit', edit_todo_list_path(todo_list) %>
          <%= link_to 'Destroy', todo_list, method: :delete, data: { confirm: 'Are you sure?' } %>
        </td>
      </tr>
    <% end %>
  </tbody>

Any help would be appreciated in solving this issue! Thanks.

1 Answer

Francois van der Hoven
Francois van der Hoven
2,026 Points

Hi Robert, Are you using RSpec? I am not sure if your spec file is named correctly. I use the naming convention my_test_abc_spec.rb, so there is only only dot in the name. Also I run my tests like this:

rspec path/to/file/my_test_abc_spec.rb 

if I only want to test that specific file.