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

[SOLVED] Testing fails, but code runs fine.

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

This code produces 1 failure in testing. Even though it's the same as what Jason wrote in the video. Here's the errors:

Finished in 0.34686 seconds
2 examples, 1 failure

Failed examples:

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

Randomized with seed 57648

The line 14 it mentioned is the beginning of the block of code I provided above. As you can see, the error doesn't provide much help. However, the app works just like it should if i go there myself. Here is a screenshot: http://imgur.com/kGVe3zz

Can someone help me out here? Is it my code acting up? Or is it the difference in the versions causing this? By the way, my system is running Rails 4.2.5.1, and I've required the rspec-rails gem to be version 2.0 through the Gemfile:

group :development, :test do
    gem 'rspec-rails', '~> 2.0' 
end

group :test do
    gem 'capybara', '~> 2.1.0'
end

HI Abby,

There's possibly some more error text generated than that - can you paste that in?

Steve.

Yup. Found it. It says uninitialized constant ToDoList.

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:17:in `block (2 levels) in <top (required)>'

I simply had to use TodoList.count instead of ToDoList.count. Silly me!

Ah, yes. That's why you were getting a syntax failure rather than a test failure. Glad you got it fixed. :+1: