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

Audrey Barker
Audrey Barker
2,963 Points

2 failures when I run rspec

I have been stuck on the "first tests" video for over an hour and can't seem to figure out the issue.

Every time I run rspec, i get these two failures:

Failures:

1) Creating todo lists redirects to the todo list 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:12: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:27:in `block (2 levels) in <top (required)>'

Here's what my code looks like:

'' 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 ''

1 Answer

Daniel Pointecker
Daniel Pointecker
19,593 Points

Hi Audrey,

I think this does not work in case of a typo. try to change:

click_button "Create Todo List"

to

click_button "Create Todo list"

The string has to be exactly as on the button and you must change each appearance.