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 trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Editing Todo Items

G. Silva
G. Silva
4,341 Points

Failure/Error: expect(todo_item.content).to have_content("Lots of Milk")

I can't figure this one out:

Error MSG:

Editing todo items is successful with valid content (FAILED - 1)

Failures:

1) Editing todo items is successful with valid content Failure/Error: expect(todo_item.content).to have_content("Lots of Milk") expected to find text "Lots of Milk" in "Milk" # ./spec/features/todo_items/edit_spec.rb:22:in `block (2 levels) in <top (required)>'

Finished in 0.09788 seconds 1 example, 1 failure

Failed examples:

rspec ./spec/features/todo_items/edit_spec.rb:13 # Editing todo items is successful with valid content

edit_spec.rb file:

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.")
expect(todo_item.content).to have_content("Lots of Milk")

end end

Hello,

From the looks of it, you might be getting an error in your application when you click save. I'm thinking this because "block (2 levels) in " seems like its a fragment of an error message. What happens when you do this manually? Also, when you do it manually, what is the value of todo_item.content?

G. Silva
G. Silva
4,341 Points

Hi James,

When I do it manually, a new item get saved and the old item does not disappear. Seems like my editing link it is not editing rather is creating a new item.

It does sound like either your link is going to the new and create actions or your edit or update actions are creating a new item instead of editing the current item then. To help further, its likely we'll need to see your controller and possibly view files.

G. Silva
G. Silva
4,341 Points

Hi James,

Thank you so much for your insight. Yes, the problem was on my controller. I was able to find a typo on my update method.

Thanks for your help! Have a great weekend! : )

Glad I could help. Have fun with Rails development.

1 Answer

Daniel Cunningham
Daniel Cunningham
21,109 Points

Your code is a little difficult to read, but it LOOKS like you wrote

require 'spec_helper'

describe "Editing todo items" do
   let!(:todolist) {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
  visittodo_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.")
   expect(todo_item.content).to have_content("Lots of Milk")

   end
end

I just copied and pasted your content and tried to clean it up a little. It looks like there is a syntax error in calling "visit_todo_list". Are there any other warnings that suggest a syntax error in the test?