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 trialSharon Evans
8,683 PointsFailure/Error: expect(page).to have_content("Content can't be blank.")
I am receiving this error:
1) Editing todo items is unsuccessful with no content Failure/Error: expect(page).to have_content("Content cannot be blank.") expected to find text "Content cannot be blank." in "That todo list item could not be saved. 2 errors prohibited this todo item from being saved: Content can't be blank Content is too short (minimum is 2 characters) Content" # ./spec/features/todo_items/edit_spec.rb:35:in `block (2 levels) in <top (required)>'
Here is my code from edit_spec.rb
require 'spec_helper'
describe "Editing todo items" do
let!(:todo_list) { TodoList.create(title: "Grocery list", description: "Groceries") }
let!(:todo_item) { todo_list.todo_items.create(content: "Milk") }
def visit_todo_list(list)
visit "/todo_lists"
within "#todo_list_#{list.id}" do
click_link "List Items"
end
end
it "is successful with valid content" do
visit_todo_list(todo_list)
within("#todo_item_#{todo_item.id}") do
click_link "Edit"
end
fill_in "Content", with: "Lots of Milk"
click_button "Save"
expect(page).to have_content("Saved todo list item.")
todo_item.reload
expect(todo_item.content).to eq("Lots of Milk")
end
it "is unsuccessful with no content" do
visit_todo_list(todo_list)
within("#todo_item_#{todo_item.id}") do
click_link "Edit"
end
fill_in "Content", with: ""
click_button "Save"
expect(page).to_not have_content("Saved todo list item.")
expect(page).to have_content("Content cannot be blank.")
todo_item.reload
expect(todo_item.content).to eq("Milk")
end
end
Can someone please help?
1 Answer
Tommy Bregar
10,847 PointsTake a look at the content you expect to see, and take a look at the errors prohibiting the item from being saved, the two are not equal:
Expected:
expect(page).to have_content("Content cannot be blank.")
The error being rendered: "2 errors prohibited this todo item from being saved: Content can't be blank"
So try changing your spec to the following:
expect(page).to have_content("Content can't be blank")
Let us know!
Sharon Evans
8,683 PointsSharon Evans
8,683 PointsTommy Bregar