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.


William Bruntrager
William Bruntrager
11,473 Points

Test Fails, todo_list ID does not match HTML

EDIT: This turned out to be a simple problem of spelling, not nearly as complicated as I thought when I posted the question.

rspec fails by looking for a page element that is not there. I have noticed that in creating the Todo lists manually, the id number starts from the previous list, even if that list has been deleted. Yet in the test, it seems to set the id to 1. What can I do so that the newly created list has the proper id?

Failure dialog:

$ rspec spec/features/todo_lists/edit_spec.rb


  1) Editing todo lists updates a todo list successfully with correct information
     Failure/Error: within "#todo_lists_#{todo_list.id}" do

       Unable to find css "#todo_lists_1"
     # ./spec/features/todo_lists/edit_spec.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.20001 seconds (files took 11.93 seconds to load)
1 example, 1 failure


require 'rails_helper'

describe "Editing todo lists" do
  it "updates a todo list successfully with correct information" do
    todo_list = TodoList.create(title: "Groceries", description: "Grocery list.")
    visit "/todo_lists"
    within "#todo_lists_#{todo_list.id}" do
      click_link "Edit"

    fill_in "Title", with: "New title"
    fill_in "Description", with: "New description"
    click_button "Update Todo list"

    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")

On line 5 of edit_spec.rb the todo_list is set to the newly created list, yet later the id returned by todo_list.id doesn't match. How can I fix this?

1 Answer

Hi William,

I think that needs to be a singular todo_list:

           ^ # no s

Let me know if that fixes it?


William Bruntrager
William Bruntrager
11,473 Points

Ach! Good catch, that fixed it. Next time I'll have to check spelling before I assume the problem is much more complicated than it really is.

Glad it worked. :-)