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 Creating Methods in Tests

Brian Patterson
Brian Patterson
19,588 Points

Don't know why I am getting this error.

Not sure why I am getting this error

Finished in 0.4482 seconds
5 examples, 5 failures

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:17 # Creating todo lists redirects to the todo list index page on success
rspec ./spec/features/todo_lists/create_spec.rb:34 # 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:22 # Creating todo lists displays an error when the todo list has no title
rspec ./spec/features/todo_lists/create_spec.rb:58 # Creating todo lists displays an error when the todo list has no description
rspec ./spec/features/todo_lists/create_spec.rb:46 # Creating todo lists displays an error when the todo list has no description

Randomized with seed 13409

I pretty much copied this word for word in his example.

''' require 'spec_helper'

describe "Creating todo lists" do def create_todo_list(options={}) options[:title] ||= "My Todo Lists" 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 Lists") 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

Brian Patterson
Brian Patterson
19,588 Points

I am not getting this error now.

Failures:

  1) Creating todo lists displays an error when the todo list has no description
     Failure/Error: expect(page).to have_content("error")
       expected to find text "error" in "Todo list was successfully created. Title: Grocery list Description: Food Edit | Back"
     # ./spec/features/todo_lists/create_spec.rb:63:in `block (2 levels) in <top (required)>'

This is my amended code.

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

3 Answers

Alan Matthews
Alan Matthews
10,161 Points

No worries, I can read the error but I just want to see the specs in question. Example:

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

Also, these specs are testing for the description being empty but one has description as food:

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
Alan Matthews
Alan Matthews
10,161 Points

It looks like the error is saying it can't find "error" on the page and it's finding this:

Todo list was successfully created. Title: Grocery list Description: Food Edit | Back"

Description is being filled in with Food Edit | Back for some reason, take a look at your view and the form for syntax errors.

Also, if you just want to post the error and make sure it's included in the code markdown format, it's hard to read everything as is.

Brian Patterson
Brian Patterson
19,588 Points

When I filled the description with a "" it passed. I take it that's not the problem. I am at a loss as to where the syntax error is.

Alan Matthews
Alan Matthews
10,161 Points

Anyway can you post just the failing test and the revised test? Just the parts of the spec you have in question, not all of the spec.

Brian Patterson
Brian Patterson
19,588 Points

1) Creating todo lists displays an error when the todo list has no description Failure/Error: expect(page).to have_content("error") expected to find text "error" in "Todo list was successfully created. Title: Grocery list Description: Food Edit | Back" # ./spec/features/todo_lists/create_spec.rb:63:in `block (2 levels) in ' Not sure what you mean. Sorry for being a bit thick!! Here is the error I'm getting for the code above.