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 Deleting Todo Lists

Evan Cooke
Evan Cooke
3,801 Points

Deleting Spec

I get this error when I run the delete spec:

Failures:

1) Deleting todo lists is successful when clicking the destroy link Failure/Error: expect(page).to_not have_content(todo_list.title) expected not to find text "Groceries" in "Listing todo_lists Title Description Groceries Grocery list. Show Edit Destroy Groceries Grocery list. Show Edit Destroy Groceries Grocery list. Show Edit Destroy Groceries Grocery list. Show Edit Destroy Groceries Grocery list. Show Edit Destroy New Todo list" # ./spec/features/todo_lists/destroy_spec.rb:13:in `block (2 levels) in <top (required)>'

My code in destroy_spec.rb is:

require 'spec_helper'

describe "Deleting todo lists" do
    let!(:todo_list) {TodoList.create(title: "Groceries", description: "Grocery list.")
}

    it "is successful when clicking the destroy link" do
        visit "/todo_lists"

        within "#todo_list_#{todo_list.id}" do
            click_link "Destroy"
        end
        expect(page).to_not have_content(todo_list.title)
        expect(TodoList.count).to eq(0)
    end
end

2 Answers

Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points

It seems your testing database doesn't get empty. There are five rows in your error messages.

1) Deleting todo lists is successful when clicking the destroy link 

Failure/Error: expect(page).to_not have_content(todo_list.title) expected not to find text "Groceries" in
 "Listing todo_lists Title Description 
 Groceries Grocery list. Show Edit Destroy 
 Groceries Grocery list. Show Edit Destroy 
 Groceries Grocery list. Show Edit Destroy 
 Groceries Grocery list. Show Edit Destroy 
 Groceries Grocery list. Show Edit Destroy 
 New Todo list" 
 # ./spec/features/todo_lists/destroy_spec.rb:13:in `block (2 levels) in '

testing db is separate from development db, and supposed to start clean for each example.

Could you explain this a bit more? I think this is what's happening to me, too, and I can't figure out how to fix it. It certainly isn't correct, but I believe I did exactly what Jason Seifer said in the video.

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Jim Withington try running bin/rake db:test:prepare and running your test again. If your test database is acting funny, like in this case, that can help clear it up.

Thanks, Jason!