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

5 examples, 5 failures

I believe my create_spec.rb is the same as what Jason is showing in the video but when i run the program in the terminal I receive 5 examples and 5 failures. I apologize if this is difficult to read but I'm not sure how to properly format these posts when many of the new line characters don't appear and half of the code appears in black boxes.

my code is :

require 'spec_helper'

describe "Creating todo lists" do
  def create_todo_list(options={})
    options[:title] ||= "My todo list"
    options[:description] ||= "This is my todo list."

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

    fill_in "Title", with: options[:title]
    fill_in "Description", with: options[:description]
    click_button "Create Todo list"
  end


  it "redirects to the todo list index page on success" do
    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)

    create_todo_list title: ""

    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)

    create_todo_list title: "Hi"

    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 no description" do
    expect(TodoList.count).to eq(0)

    create_todo_list title: "Grocery list", description: ""

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

    visit "/todo_lists"
    expect(page).to_not have_content("Grocery list")
  end

  it "displays an error when the todo list has no description" do
    expect(TodoList.count).to eq(0)

    create_todo_list title: "Grocery list", description: "Food"

    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

and the error message I am receiving is:

FFFFF

Failures:

  1) Creating todo lists redirects to the todo list index page on success
     Failure/Error: expect(page).to have_content("My todo list")
     Capybara::ElementNotFound:
       Unable to find xpath "/html"
     # ./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 description
     Failure/Error: expect(page).to have_content("error")
     Capybara::ElementNotFound:
       Unable to find xpath "/html"
     # ./spec/features/todo_lists/create_spec.rb:56:in `block (2 levels) in <top (required)>'

  3) Creating todo lists displays an error when the todo list has a title less than 3 characters
     Failure/Error: expect(page).to have_content("error")
     Capybara::ElementNotFound:
       Unable to find xpath "/html"
     # ./spec/features/todo_lists/create_spec.rb:32:in `block (2 levels) in <top (required)>'

  4) Creating todo lists displays an error when the todo list has no description
     Failure/Error: expect(page).to have_content("error")
     Capybara::ElementNotFound:
       Unable to find xpath "/html"
     # ./spec/features/todo_lists/create_spec.rb:44:in `block (2 levels) in <top (required)>'

  5) Creating todo lists displays an error when the todo list has no title
     Failure/Error: expect(page).to have_content("error")
     Capybara::ElementNotFound:
       Unable to find xpath "/html"
     # ./spec/features/todo_lists/create_spec.rb:20:in `block (2 levels) in <top (required)>'

Finished in 0.03426 seconds
5 examples, 5 failures

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:10 # Creating todo lists redirects to the todo list index page on success
rspec ./spec/features/todo_lists/create_spec.rb:51 # Creating todo lists displays an error when the todo list has no description
rspec ./spec/features/todo_lists/create_spec.rb:27 # Creating todo lists displays an error when the todo list has a title less than 3 characters
rspec ./spec/features/todo_lists/create_spec.rb:39 # Creating todo lists displays an error when the todo list has no description
rspec ./spec/features/todo_lists/create_spec.rb:15 # Creating todo lists displays an error when the todo list has no title

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

Try replacing the "/todo_lists" lines with this:

visit todo_lists_path

I just fixed the problem by changing the line

expect(page).to have_content("New todo_list")

to

expect(page).to have_content("New Todo List")

I noticed that after clicking the new todo list button the title of the page was "New Todo List" instead of "New todo_list" like in the videos. I don't believe I strayed from Jason's walkthrough so is it possible that the scaffold created something different because I am using Ruby 4.2.0 instead of 4.0.0? Or is there likely another explanation hidden away in my code because I cannot find out where my code has set this.