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 Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Write Our First Tests

Daniel Gonzalez
Daniel Gonzalez
5,312 Points

Failure/Error: expect(page).to have_content("New Todo_list") expected to find text "New Todo_list" in "New todo error

I keep receiving this error when running test after finishing editing the create_spec.rb file. I can't seem to find anything wrong with what I've written.

describe "Creating todo lists" do
    it "redirects to the todo list index page on success" do
    visit "/todo_lists"
    click_link "New Todo list"
    expect(page).to have_content("New Todo_list")

    fill_in "Title", with: "My Todo List"
    fill_in "Description", with: "This is what I'm doing Today"
    click_button "Create Todo list"

    expect(page).to have_content("My todo list")
    end
    it "displays an error when the todo list has no title" do
        expect(TodoList.count).to eq(0)

        visit "/todo_lists"
        click_link "New Todo list"
        expect(page).to have_content("New Todo_list")

        fill_in "Title", with: ""
        fill_in "Description", with: "This is what I'm doing Today"
        click_button "Create Todo list"

        expect(page).to have_content("error")
        expect(TodoList.count).to eq(0)

        visit "/todo_lists"
        expect(page).to_not have_content("This is what I am doing today")

    end
end

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Can you show your views that are visited using this test? A lot can be wrong here. You have lots of expectations, but we don't know which line exactly is failing. Example:

This will fail 100%:

fill_in "Title", with: "My Todo List"
    fill_in "Description", with: "This is what I'm doing Today"
    click_button "Create Todo list"

    expect(page).to have_content("My todo list")

because you are filling in with "List" and expecting there to be "list" - upper and lower case letters matter.

Please do this whole test yourself in the browser to see if you really see the content that you are expecting in the tests, such as "New Todo_list" instead of "New Todo list" (without underscore).