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 trialChris Dziewa
17,781 PointsSolved...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
17,781 PointsSolved 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
16,511 PointsThanks so much for posting...I did the exact same thing, and it was driving me mad!
Chris Dziewa
17,781 PointsHa! 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!
Chris Dziewa
17,781 PointsChris Dziewa
17,781 Pointssolved!