Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Viewing Todo Items: Part 1

Chris Dziewa
Chris Dziewa
17,781 Points

Solved...Capybara: Unable to find css error

I have tried everything with the code from this video. I still can't get my test to pass even though the functionality is correct. I continuously get this failure:

Viewing todo items displays no items when a todo list is empty Failure/Error: within "#todo_list_#{todo_list.id}" do Capybara::ElementNotFound: Unable to find css "#todo_list_" # ./spec/features/todo_items/index_spec.rb:8:in `block (2 levels) in <top (required)>'

I have checked the source code and the id is correct there. It seems like the test isn't passing in the correct list id.

Here is my index_spec.rb file:

require 'spec_helper'


describe "Viewing todo items" do 
    let!(:todo_list) { TodoList.create(title: "Grocery list", description: "Groceries") }
    it "displays no items when a todo list is empty" do 
        visit "/todo_lists"
        within "#todo_list_#{todo_list.id}" do 
            click_link "List Items"
        end
        expect(page).to have_content("TodoItems#index")
    end
end

Here is my index.html.erb inside todo_lists view:

<table>
  <thead>
    <tr>
      <th>Title</th>
      <th>Description</th>
      <th></th>
    </tr>
  </thead>

  <tbody>
    <% @todo_lists.each do |todo_list| %>
      <tr id="<%= dom_id(todo_list) %>">
        <td><%= todo_list.title %></td>
        <td><%= todo_list.description %></td>
        <td>
          <%= link_to "List Items", todo_list_todo_items_path(todo_list) %>
          <%= 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>
</table>

<br>

<%= link_to 'New Todo list', new_todo_list_path %>

I can provide anything else that would be helpful. Thanks!

2 Answers

Chris Dziewa
Chris Dziewa
17,781 Points

Solved it! I realize now that I had chosen to validate the description length to be a minimum of 10 characters even though the tutorial was for 6. When Jason set the description to be 'Groceries' for the test, I was one character short so nothing was created. I guess that's what I get for customizing a tutorial!

Brett Petersen
Brett Petersen
16,511 Points

Thanks so much for posting...I did the exact same thing, and it was driving me mad!

Chris Dziewa
Chris Dziewa
17,781 Points

Ha! Gotta love those tiny mistakes that make you spend hours running in circles. Then you step away and come back and shake your head when you realize it was a typo or something. Glad this helped you though!