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 Write Our First Tests

Anthony Ho
Anthony Ho
10,228 Points

Error in #15

I still have a failure after

class TodoList < ActiveRecord::Base

    validates :title, presence: true
end

Here's is my create_spec.rb

require 'spec_helper'

describe "Creating todo lists" do
   it "redirects to the todo list index page on success" do
       visit "/todo_lists"
       click_link "New Todo list"
       expect(page).to have_content("New todo_list")

    fill_in "Title", with: "My todo list"
     fill_in "Description", with: "This is what I'm doing today."
    click_button "Create Todo list"

    expect(page).to have_content("My todo list")
    end

    it "displays an error when the todo list has no title" do

    expect(Todolist.count).to eq(0)

        visit "/todo_lists"
       click_link "New Todo list"
       expect(page).to have_content("New todo_list")

    fill_in "Title", with: ""
    fill_in "Description", with: "This is what I'm doing today."
    click_button "Create Todo list"
    expect(page).to have_content("error")
    expect(TodoList.count).to eq(0)

    visit "/todo_lists"
    expect(page).to_not have_content("This is what I'm doing today.")
        end

end

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Here's your mistake, line 18:

expect(Todolist.count).to eq(0)

should be:

expect(TodoList.count).to eq(0)

After this change there are 0 failures. A simple typo :)

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I think this:

expect(Todolist).to eq(0)

Should be something like this:

expect(Todolist, :count).to eq(0)

or

expect(Todolist.count).to eq(0)

(note that you have this expectation twice, so change it in both places)

Anthony Ho
Anthony Ho
10,228 Points

sorry I still got a failure:

2 examples, 1 failure

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:15 # Create todo lists displays an error when the todo list has no title

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

What is the content of the whole error? You have 4 expectations there and I don't know which one is failing now.

Also, please open the browser and try doing this test yourself and see if there is a word "error" anywhere when you create an empty list.

Anthony Ho
Anthony Ho
10,228 Points

That was the error shown on the terminal

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

No, there has to be more text above the lines that you quoted here. These lines may look cryptic, like gibberish, but they hold the key to the solution. You can also publish the project on GitHub so that I could run the app myself and see what's going on.