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

Jason Law
Jason Law
15,254 Points

Rspec test fails for delete todo list

When I run Rspec for Deleting todo lists is successful when clicking the destroy link, I get the following error.

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 "Todo list was successfully destroyed. 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 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 is as follows...

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

Does anyone know why I am getting errors? I noticed that rspec thinks there are 10 todolists.

1 Answer

Tom Sager
Tom Sager
18,987 Points

It is not obvious because the rspec error message shows the page text but not the HTML. It looks like there are ten remaining todo lists, and each is named "Groceries."

Try resetting your test database (bundle exec rake db:reset RAILS_ENV=test) and try it again. You can also look through your test log file to see what database transactions are occurring or failing.

It is very useful to have Capybara to save a screen shot on every error. Google "capybara save_and_show_page" to see how to set this up.

Good luck!