Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Gísli Guðmundsson
2,640 PointsI am trying out create_spec.rb and when I try to run it I get an Failure/Error
rspec spec/features/todo_lists/create_spec.rb .FFF
Failures:
1) Creating todo lists displays an error when the todo list has no description Failure/Error: expect(TodoList.count).to eq(0)
expected: 0
got: 7
(compared using ==)
# ./spec/features/todo_lists/create_spec.rb:63:in `block (2 levels) in <top (required)>'
2) Creating todo lists displays an error when the todo list has no title Failure/Error: expect(TodoList.count).to eq(0)
expected: 0
got: 7
(compared using ==)
# ./spec/features/todo_lists/create_spec.rb:24:in `block (2 levels) in <top (required)>'
3) Creating todo lists displays an error when the todo list has title less than 3 characters Failure/Error: expect(TodoList.count).to eq(0)
expected: 0
got: 7
(compared using ==)
# ./spec/features/todo_lists/create_spec.rb:42:in `block (2 levels) in <top (required)>'
Finished in 0.07668 seconds 4 examples, 3 failures
Failed examples:
rspec ./spec/features/todo_lists/create_spec.rb:62 # Creating todo lists displays an error when the todo list has no description rspec ./spec/features/todo_lists/create_spec.rb:23 # Creating todo lists displays an error when the todo list has no title rspec ./spec/features/todo_lists/create_spec.rb:41 # Creating todo lists displays an error when the todo list has title less than 3 characters
Here is the code for create_spec.rb
require 'spec_helper'
RSpec.configure do |c| c.fail_fast = false c.use_transactional_fixtures = true c.raise_errors_for_deprecations! c.expose_current_running_example_as :example end
RSpec.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: "Hi"
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
it "displays an error when the todo list has title less than 3 characters" 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: "Hi"
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
it "displays an error when the todo list has no description" 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: "Grocery List"
fill_in "Description", with: ""
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("Grocery List")
end
end
Here is the code for todo_list.rb model
class TodoList < ActiveRecord::Base validates :title, presence: true
validates :title, length: { minimum: 3 }
validates :description, presence: true
end
2 Answers

Kang-Kyu Lee
52,045 PointsSeems like
expect(TodoList.count).to eq(0)
at the beginning of each it (example) not working. so it says, The test db is not rolling back after each test (have 7 entities) as it supposed to be. However this is not a problem of code, of database cleaning.
why does this happen? Jason Seifer

Kang-Kyu Lee
52,045 Pointsit "displays an error when the todo list has no title"
it "displays an error when the todo list has title less than 3 characters"
these two are the same on your code by the way