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 trialrigzin norboo
11,059 PointsUnable to find css "todo_item_2" in complete_spec.rb
My test fails for "with completed items". I did exactly the same as Jason but when i run rspec it says:
Failure/Error: within("todo_item_#{completed_todo_item.id}") do Capybara::ElementNotFound: Unable to find css "todo_item_2"
it "show completed items as complete" do
visit_todo_list todo_list
within("todo_item_#{completed_todo_item.id}") do
expect(page).to have_content(completed_todo_item.complete_at)
end
end
it "does not give the option to mark complete" do
visit_todo_list todo_list
within("todo_item_#{completed_todo_item.id}") do
expect(page).to_not have_content("Mark Complete")
end
end
4 Answers
Steve Hunter
57,712 PointsHi Rigzin,
Your test is visiting a todo_list and is then looking at the listed todo_items to see whether there is either the content, "mark complete" or a tag for completed_at.
What is not working is the listed todo items; it is looking for todo_item_# where # is the id
of the todo_item. It is not seeing this content. Can you post the code in your corresponding view, please? It might be in todo_items/index.html.erb
, I think!
Steve.
rigzin norboo
11,059 Points<ul class="todo_items">
<% @todo_list.todo_items.each do |todo_item| %>
<li id="<%= dom_id(todo_item) %>">
<% if todo_item.completed? %>
<%= todo_item.complete_at %>
<% else %>
<%= link_to "Mark Complete", complete_todo_list_todo_item_path(@todo_list, todo_item), method: :patch %>
<% end %>
<%= todo_item.content %>
<%= link_to "Edit", edit_todo_list_todo_item_path(@todo_list, todo_item) %>
<%= link_to "Delete", todo_list_todo_item_path(@todo_list,todo_item), method: :delete, data: {confirm: "Are you sure?" } %>
</li>
<%end%>
</ul>
Steve Hunter
57,712 PointsYeah - there's no id on the page which is why your test is failing.
You've got a dom_id
there, so try the following:
it "shows completed items as complete" do
visit_todo_list todo_list
within dom_id_for(completed_todo_item) do
expect(page).to have_content(completed_todo_item.completed_at)
end
end
it "does not give the option to mark complete" do
visit_todo_list todo_list
within dom_id_for(completed_todo_item) do
expect(page).to_not have_content("Mark Complete")
end
end
That's not looking for a specific number against each item, but is using specific items for the test.
Steve.
rigzin norboo
11,059 PointsBut i don't have dom_id_for method. Jason made a separate helper in shared file with a method dom_id_for in it, but i didn't find it necessary so i didn't made it . And what do you mean by "there's no id on the page". I am assigning id to the li tag through dom_id(todo_item) and that's what i am looking for in my test within("todo_item_#{completed_todo_item.id}") , so my test should have worked. Why do i need dom_id_for method for it.