Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBrian Patterson
19,588 PointsDon'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
3 Answers
Alan Matthews
10,161 PointsNo 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
10,161 PointsIt 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
19,588 PointsWhen 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
10,161 PointsAnyway 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
19,588 Points1) 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.
Brian Patterson
19,588 PointsBrian Patterson
19,588 PointsI am not getting this error now.
This is my amended code.