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 Set up Git and Add Gems

G. Silva
G. Silva
4,341 Points

test failure even after adding validation

Error MSG:

Failures:

1) Creating todo lists displays an error when the todo list has no description Failure/Error: expect (page).to have_content("New todo list") NoMethodError: undefined method to' for #<Capybara::Session> # ./spec/features/todo_lists/create_spec.rb:58:inblock (2 levels) in <top (required)>'

2) Creating todo lists redirects to the todo list index page on success Failure/Error: expect (page).to have_content("New todo_list") NoMethodError: undefined method to' for #<Capybara::Session> # ./spec/features/todo_lists/create_spec.rb:7:inblock (2 levels) in <top (required)>'

3) Creating todo lists displays an error when the todo list has no title Failure/Error: expect (page).to have_content("New todo_list") NoMethodError: undefined method to' for #<Capybara::Session> # ./spec/features/todo_lists/create_spec.rb:22:inblock (2 levels) in <top (required)>'

4) Creating todo lists displays an error when the todo list has a title less than 3 characters Failure/Error: expect (TodoList.count).to eq(0) NoMethodError: undefined method to' for 0:Fixnum # ./spec/features/todo_lists/create_spec.rb:36:inblock (2 levels) in <top (required)>'

Finished in 0.06127 seconds 4 examples, 4 failures

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:53 # Creating todo lists displays an error when the todo list has no description rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating todo lists redirects to the todo list index page on success rspec ./spec/features/todo_lists/create_spec.rb:17 # Creating todo lists displays an error when the todo list has no title rspec ./spec/features/todo_lists/create_spec.rb:35 # Creating todo lists displays an error when the todo list has a title less than 3 characters

Randomized with seed 23534

CREATE SPEC FILE

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

it "displays an error when the todo list has a title less than 3 characters" 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: "Hi"
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_nots have_content("This is what I'm doing today")

end

it "displays an error when the todo list has no description" 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: "Grocery list"
fill_in "Description", with:""
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("Grocery list")

end end

1 Answer

Brandon Barrette
Brandon Barrette
20,485 Points

You can't have a space between expect and (page). Should be this:

expect(page).to have_content("This is my content")

And not this:

expect (page).to have_content("This is my content")
G. Silva
G. Silva
4,341 Points

Thanks Brandon, that solved 3 of the tests failures. Then I found a mistyped word and now all tests pass : )