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

Capybara::ElementNotFound:Unable to find css

Hello all i'm getting the following error whilst running the test in the "Viewing Todo Items Part 1 " video

Failures:

  1) 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_1"
     # ./spec/features/todo_items/index_spec.rb:8:in `block (2 levels) in <top (required)>'

This is the code that I have been trying to debug

index_spec.rb

require 'spec_helper'

describe "Viewing todo items"  do
    let!(:todo_list) {TodoList.create(title: "Grocery List of thisnkdssd ", description: "here is some bastard grocery lisiybs asidba asdb")}

    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

index.html.erb inside todo_lists directory

<h1>Listing todo_lists</h1>

<table>
  <thead>
    <tr>
      <th>Title</th>
      <th>Description</th>
      <th colspan="3"></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 %>

index.html.erb inside todo_items

<h1>TodoItems#index</h1>

<p>Find me in app/views/todo_items/index.html.erb</p>

If anyone can help me out it would be greatly appreciated.

I have been working on this now for over a week!

K*

2 Answers

Try this:

within "#todo_list_#{todo_list.id}"do

(additional # before todo_list, suggesting an ID)

Wow! You are good!

I actually know why this happened. In Sublime when you enter the # it automatically gives the characters #{} - as I deleted the superfluous curly braces is must have deleted the # and not realised.

Let that be a lesson to you all!

K*