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.

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Write Our First Tests

Matt Young
Matt Young
6,348 Points

RSpec Test Failures (Capybara Error)

Neither of my tests are passing. I get the following:

Failures:

1) Creating todo lists redirects to the todo lists index page on success Failure/Error: click_button "Create Todo List" Capybara::ElementNotFound: Unable to find button "Create Todo List" # ./spec/features/todo_lists/create_spec.rb:11:in `block (2 levels) in <top (required)>'

2) Creating todo lists displays an error when the todo list has no title Failure/Error: click_button "Create Todo List" Capybara::ElementNotFound: Unable to find button "Create Todo List" # ./spec/features/todo_lists/create_spec.rb:25:in `block (2 levels) in <top (required)>'

My code:

require 'spec_helper'

describe "Creating todo lists" do
    it "redirects to the todo lists 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("Todo list was successfully created.")
    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'm doing today.")

    end
end

3 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

It looks like your button doesn't say "Create Todo List" verbatim. It's probably something like "Create Todo list" or "Create Todo_list" - run your server, navigate to that page and see what the button has on it. Underscores and capital/lowercase letters are all very important. Capybara (and programs in general) is very precise.

Matt Young
Matt Young
6,348 Points

Duh. Silly me. Thanks. It was Create Todo list NOT Create Todo List.

I am experiencing the identical error and here is the code I have:

require 'spec_helper'

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'm doing today.")
    end
end

I've combed through the spec.rb sheet multiple times and have been unable to ID the potential bug. Any thoughts?

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

You have to show us more, preferably a link to the whole app.

Hey Maciej,

Here is a link to the repository.

https://github.com/JustinHenderson88/ruby_to_do_list

There have been a few minor changes made that I haven't pushed quite yet. Let me know if this helps...thanks again!

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

You pushed some folder that contains two projects inside and I can't access todo project there.

Well another issue I'm having is how can I send you a link to the Sublime text file? I don't believe I know how to do that?...