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

Edward Poon
Edward Poon
9,313 Points

Destroy test fails when running bin/rake spec

It says that the the todo list is not being deleted even though the destroy_spec.rb test passes. I get the following error when running bin/rake spec:

Failures:

1) Deleting todo lists is successful when clicking the destroy link Failure/Error: expect(TodoList.count).to eq(0)

   expected: 0
        got: 1

   (compared using ==)
 # ./spec/features/todo_lists/destroy_spec.rb:12:in `block (2 levels) in <top (required)>'

Finished in 3.2 seconds 41 examples, 1 failure, 2 pending

Failed examples:

rspec ./spec/features/todo_lists/destroy_spec.rb:6 # Deleting todo lists is successful when clicking the destroy link

Here is the file

require 'spec_helper'

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

  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
Javier Perez
Javier Perez
3,337 Points

Hi Edward, please show us your rspec file, specifically the one failing.

Brandon Barrette
Brandon Barrette
20,485 Points

Please post your TodoList controller. There is an error in the destroy method.