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 trialNic J Muller
9,822 PointsRspec test fail
Right, so I'm trying to follow a long with sprining-Jason but seem to have hit a snag. I create the spec:
require 'spec_helper'
describe "Editing todo lists" do
it "updates todo list successfully with correct information" do
todo_list = TodoList.create(title: "Groceries", description: "Grocery list.")
visit "/todo_lists"
within "#todo_list_#{todo_list.id}" do
click_link "Edit"
end
fill_in "Title", with: "New Title"
fill_in "Description", with: "New description"
click_button "update Todo list"
todo_list.reload
expect(page).to have_content("Todo list was successfully updated.")
expect(todo_list.title).to eq("New title")
expect(todo_list.description).to eq("New description")
end
end
The index HTML looks like this:
<p id="notice"><%= notice %></p>
<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 'Show', todo_list %></td>
<td><%= link_to 'Edit', edit_todo_list_path(todo_list) %></td>
<td><%= 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 %>
When I run the text in the terminal:
Failures:
1) Editing todo lists updates todo list successfully with correct information Failure/Error: within "#todo_list_#{todo_list.id}" do Capybara::ElementNotFound: Unable to find css "#todo_list_1" # ./spec/features/todo_lists/edit_spec.rb:10:in `block (2 levels) in <top (required)>'
Finished in 0.1697 seconds 1 example, 1 failure
Failed examples:
rspec ./spec/features/todo_lists/edit_spec.rb:4 # Editing todo lists updates todo list successfully with correct information
Randomized with seed 50778
Nicholiss-MacBook-Pro:odot Nicholis$
When I look in the dev tools I see that the dom_id is incrementing from the last save. For example todo_list_6 and capybara is looking by default for todo_list_1. Hence the error.
I'm stumped. Any thoughts?
3 Answers
Ben Ricker
Courses Plus Student 348 Pointsfill_in "Title", with: "New Title"
expect(todo_list.title).to eq("New title")
You will fail because you're filling in "New Title" (capitalized title) but expecting "New title") (not capitalized title)
Andrew Stelmach
12,583 PointsHmm, it's hard to say without looking at the actual output of:
<tr id="<%= dom_id(todo_list) %> " >
This must be where the problem lies.
That line will result in something different in the actual html that is delivered to the client (which will be the browser in your case).
So, you need to right click on the page in your browser and inspect the html that appears. I would bet that id = todo_list_1
isn't found anywhere?
Andrew Stelmach
12,583 PointsIf you have a Github repo for this, post it up.
Anna Goldberg
800 PointsI'm having the same problem. Has anyone figured this one out?
Andrew Stelmach
12,583 PointsAndrew Stelmach
12,583 PointsThat is a strange one. Do you have a github repo for it? If not, now might be a good time to learn how to make one! I could then clone it down and fix it (hopefully)!