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

Kern Tallett
Kern Tallett
10,012 Points

Says unitialized constant Todolist but cant work out how to intialize it. Any help?

Here is the terminal

kerns-mbp:odot Kern$ bin/rspec spec/features/todo_lists/create_spec.rb [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. .F

Failures:

1) Creating todo lists displays an error when the todo list has no title Failure/Error: expect(Todolist.count).to eq(0) NameError: uninitialized constant Todolist # ./spec/features/todo_lists/create_spec.rb:20:in `block (2 levels) in <top (required)>'

Finished in 0.08714 seconds 2 examples, 1 failure

Failed examples:

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

Here is my create_spec.rb file

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 am 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 am 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

here is my todo_list.rb file

class TodoList < ActiveRecord::Base validates :title, presence: true end

3 Answers

Do you have a a class called Todolist somewhere?

Kern Tallett
Kern Tallett
10,012 Points

I have followed the steps exactly so no. I thought it was because I hadn't set up a class but just didn't understand why. I am not fully understanding this currently as well as the other languages. The managing on multiple files. All I can think I have missed a step or made a mistake just can't see where.