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

NameError: uninitialized constant TodoList

I'm getting the following error when trying to run the tests in the index_spec.rb.

NameError: uninitialized constant TodoList # ./spec/features/todo_items/index_spec.rb:4:in `block (2 levels) in <top (required)>'

I've checked the spelling of the TodoList and it is spelled correctly. Anyone have any ideas?

Angela Visnesky
Angela Visnesky
20,927 Points

Hi Shawn! I have run into a lot of errors as I follow along. Most of them are spacing issues. If you post a snippet of your code, we can see where your issue is.

1 Answer

Here is my index_spec.rb require 'spec_helper'

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

  it 'displays no items when a todo list is empty' do
    visit '/todo_lists'
    within "#todo_list_#{todo_list.id}" do
      click_link 'List Items'
    end
    expect(page).to have_content('TodoItems#Index')
  end
end

The error I'm getting is pointing me to line 4, which is the line to create the list.

[SOLVED] I needed to add require 'rails_helper' to the file and that fixed my problem.