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

John Stoveld
John Stoveld
4,203 Points

28 Failed tests??? Rspec kicking back errors.

When I do our initial test for rspec It spits out all these errors...

3 deprecation warnings total

Finished in 0.05223 seconds
30 examples, 28 failures, 2 pending

Failed examples:

rspec ./spec/controllers/todo_lists_controller_spec.rb:34 # TodoListsController GET index assigns all todo_lists as @todo_lists
rspec ./spec/controllers/todo_lists_controller_spec.rb:42 # TodoListsController GET show assigns the requested todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:50 # TodoListsController GET new assigns a new todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:57 # TodoListsController GET edit assigns the requested todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:66 # TodoListsController POST create with valid params creates a new TodoList
rspec ./spec/controllers/todo_lists_controller_spec.rb:72 # TodoListsController POST create with valid params assigns a newly created todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:78 # TodoListsController POST create with valid params redirects to the created todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:85 # TodoListsController POST create with invalid params assigns a newly created but unsaved todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:92 # TodoListsController POST create with invalid params re-renders the 'new' template
rspec ./spec/controllers/todo_lists_controller_spec.rb:103 # TodoListsController PUT update with valid params updates the requested todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:113 # TodoListsController PUT update with valid params assigns the requested todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:119 # TodoListsController PUT update with valid params redirects to the todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:127 # TodoListsController PUT update with invalid params assigns the todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:135 # TodoListsController PUT update with invalid params re-renders the 'edit' template
rspec ./spec/controllers/todo_lists_controller_spec.rb:146 # TodoListsController DELETE destroy destroys the requested todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:153 # TodoListsController DELETE destroy redirects to the todo_lists list
rspec ./spec/requests/todo_lists_spec.rb:5 # TodoLists GET /todo_lists works! (now write some real specs)
rspec ./spec/routing/todo_lists_routing_spec.rb:6 # TodoListsController routing routes to #index
rspec ./spec/routing/todo_lists_routing_spec.rb:10 # TodoListsController routing routes to #new
rspec ./spec/routing/todo_lists_routing_spec.rb:14 # TodoListsController routing routes to #show
rspec ./spec/routing/todo_lists_routing_spec.rb:18 # TodoListsController routing routes to #edit
rspec ./spec/routing/todo_lists_routing_spec.rb:22 # TodoListsController routing routes to #create
rspec ./spec/routing/todo_lists_routing_spec.rb:26 # TodoListsController routing routes to #update
rspec ./spec/routing/todo_lists_routing_spec.rb:30 # TodoListsController routing routes to #destroy
rspec ./spec/views/todo_lists/edit.html.erb_spec.rb:11 # todo_lists/edit renders the edit todo_list form
rspec ./spec/views/todo_lists/index.html.erb_spec.rb:17 # todo_lists/index renders a list of todo_lists
rspec ./spec/views/todo_lists/new.html.erb_spec.rb:11 # todo_lists/new renders new todo_list form
rspec ./spec/views/todo_lists/show.html.erb_spec.rb:11 # todo_lists/show renders attributes in <p>
/Users/JS/.rvm/rubies/ruby-2.2.0/bin/ruby -S rspec ./spec/controllers/todo_lists_controller_spec.rb ./spec/helpers/todo_lists_helper_spec.rb ./spec/models/todo_list_spec.rb ./spec/requests/todo_lists_spec.rb ./spec/routing/todo_lists_routing_spec.rb ./spec/views/todo_lists/edit.html.erb_spec.rb ./spec/views/todo_lists/index.html.erb_spec.rb ./spec/views/todo_lists/new.html.erb_spec.rb ./spec/views/todo_lists/show.html.erb_spec.rb failed

4 Answers

Tim Knight
Tim Knight
28,888 Points

John,

This tells me that you haven't added the validation in your TodoList model for these tests to pass. Open up app/models/todo_list.rb and and make sure the two validates lines are somewhere within your class...

class TodoList < ActiveRecord::Base
  validates :title,       presence: true, length: { minimum: 3 }
  validates :description, presence: true, length: { minimum: 5 }

  # Other code
end
John Stoveld
John Stoveld
4,203 Points

You sir -

Are a majestic beastly brilliant man.

May the bar treat you well in the art of taking people home tonight.

JSs-MacBook-Pro:odot JS$ bin/rspec spec/features/todo_lists/create_spec.rb
.....

Deprecation Warnings:

--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:

  - rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
    now yield the example as a block argument, and that is the recommended
    way to access the current example from those contexts.
  - The current example is now exposed via `RSpec.current_example`,
    which is accessible from any context.
  - If you can't update the code at this call site (e.g. because it is in
    an extension gem), you can use this snippet to continue making this
    method available in RSpec 2.99 and RSpec 3:

      RSpec.configure do |c|
        c.expose_current_running_example_as :example
      end

(Called from /Users/JS/.rvm/gems/ruby-2.2.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:

  - rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
    now yield the example as a block argument, and that is the recommended
    way to access the current example from those contexts.
  - The current example is now exposed via `RSpec.current_example`,
    which is accessible from any context.
  - If you can't update the code at this call site (e.g. because it is in
    an extension gem), you can use this snippet to continue making this
    method available in RSpec 2.99 and RSpec 3:

      RSpec.configure do |c|
        c.expose_current_running_example_as :example
      end

(Called from /Users/JS/.rvm/gems/ruby-2.2.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:21:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

2 deprecation warnings total

Finished in 0.20973 seconds
5 examples, 0 failures

Randomized with seed 13592
Tim Knight
Tim Knight
28,888 Points

Awesome John I'm glad that worked.

Tim Knight
Tim Knight
28,888 Points

Hey John,

The todo_lists_controller_spec.rb is generated by default when you generate the scaffold. It's like that with the changes made in the project you're tests are failing because you've recently added model validation.

Open up you /spec/controllers/todo_lists_controller_spec.rb and just below the initial describe line look for the valid_attributes setting and add your description attribute. This will allow it to pass the validations that get setup during this course.

describe TodoListsController do
  let(:valid_attributes) { { "title" => "MyString", "description" => "My Description" } }

  ...
end

You'll notice that during course Jason is running specific spec tests and at the end of some videos he'll run the entire test suite and go back to address many of these issues.

John Stoveld
John Stoveld
4,203 Points

Just so I am clear -

On the below :

describe TodoListsController do

  # This should return the minimal set of attributes required to create a valid
  # TodoList. As you add validations to TodoList, be sure to
  # adjust the attributes here as well.
  let(:valid_attributes) { { "title" => "MyString" } }

  # This should return the minimal set of values that should be in the session
  # in order to pass any filters (e.g. authentication) defined in
  # TodoListsController. Be sure to keep this updated too.
  let(:valid_session) { {} }

I need to name my title for MyString in the above? Im still quite novice and have followed the courses but some of this feels like I missed something along the way some way or how...

Tim Knight
Tim Knight
28,888 Points

John, all you're doing based on my above comment is adding the "description" => "My Description" after the "title" => "MyString". You don't need to name anything just change:

let(:valid_attributes) { { "title" => "MyString" } }

To:

 let(:valid_attributes) { { "title" => "MyString", "description" => "My Description" } }

But as I mentioned, keep following along with the videos and you'll likely see Jason is running these specs and when he does he'll show you how to fix those issues.

John Stoveld
John Stoveld
4,203 Points

And I am back -

Finished the code on this unit and still cant get this to fly straight.

Followed Tim Knight's info above.

and now for spec > controllers > todo_listsx_controller_spec.rb

describe TodoListsController do

  # This should return the minimal set of attributes required to create a valid
  # TodoList. As you add validations to TodoList, be sure to
  # adjust the attributes here as well.
  let(:valid_attributes) { { "title" => "MyString", "description" => "My Description" } }

  # This should return the minimal set of values that should be in the session
  # in order to pass any filters (e.g. authentication) defined in
  # TodoListsController. Be sure to keep this updated too.
  let(:valid_session) { {} }

  describe "GET index" do
    it "assigns all todo_lists as @todo_lists" do
      todo_list = TodoList.create! valid_attributes
      get :index, {}, valid_session
      assigns(:todo_lists).should eq([todo_list])
    end
  end

and my create_spec.rb

require 'spec_helper'

describe "Creating todo lists" do
  it "redirects to the todo_ist 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'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

though here is the error i get running

bin/rspec spec/features/todo_lists/create_spec.rb

Err:

JSs-MacBook-Pro:odot JS$ bin/rspec spec/features/todo_lists/create_spec.rb
FF

Failures:

  1) Creating todo lists redirects to the todo_ist index page on success
     Failure/Error: expect(page).to have_content("New todo_list")
       expected to find text "New todo_list" in "New Todo List Title Description Back"
     # ./spec/features/todo_lists/create_spec.rb:7:in `block (2 levels) in <top (required)>'

  2) Creating todo lists displays an error when the todo list has no title
     Failure/Error: expect(page).to have_content("New todo_list")
       expected to find text "New todo_list" in "New Todo List Title Description Back"
     # ./spec/features/todo_lists/create_spec.rb:21:in `block (2 levels) in <top (required)>'

Deprecation Warnings:

--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:

  - rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
    now yield the example as a block argument, and that is the recommended
    way to access the current example from those contexts.
  - The current example is now exposed via `RSpec.current_example`,
    which is accessible from any context.
  - If you can't update the code at this call site (e.g. because it is in
    an extension gem), you can use this snippet to continue making this
    method available in RSpec 2.99 and RSpec 3:

      RSpec.configure do |c|
        c.expose_current_running_example_as :example
      end

(Called from /Users/JS/.rvm/gems/ruby-2.2.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:

  - rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
    now yield the example as a block argument, and that is the recommended
    way to access the current example from those contexts.
  - The current example is now exposed via `RSpec.current_example`,
    which is accessible from any context.
  - If you can't update the code at this call site (e.g. because it is in
    an extension gem), you can use this snippet to continue making this
    method available in RSpec 2.99 and RSpec 3:

      RSpec.configure do |c|
        c.expose_current_running_example_as :example
      end

(Called from /Users/JS/.rvm/gems/ruby-2.2.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:21:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

2 deprecation warnings total

Finished in 0.08603 seconds
2 examples, 2 failures

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating todo lists redirects to the todo_ist index page on success
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 8754

Im running out of ideas here.

Doesn't like lines 4 and 16. and they are the same commands...

Tim Knight
Tim Knight
28,888 Points

John, it might benefit you too to run through some of the coursework again in case you missed something. I'm not sure if you might have missed something through the course.

Here's my create_spec.rb that you can use and reference. Make sure that you've created the necessary code too to get things to pass in your controller and views.

require 'spec_helper'

describe "Creating todo lists" do

  def create_todo_list(options = {})
    options[:title] ||= "My todo list"
    options[:description] ||= "This is my todo list."

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

    fill_in "Title", with: options[:title]
    fill_in "Description", with: options[:description]
    click_button "Create Todo list"
  end

  it "redirects to the todo list index page on success" do
    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)

    create_todo_list title: ""

    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 a title less than 3 characters" do
    expect(TodoList.count).to eq(0)

    create_todo_list title: "Hi"

    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)

    create_todo_list title: "Grocery list", description: ""

    expect(page).to have_content("error")
    expect(TodoList.count).to eq(0)

    visit "/todo_lists"
    expect(page).to_not have_content("Grocery list")
  end

  it "displays an error when the todo list has a description less than 5 characters." do
    expect(TodoList.count).to eq(0)

    create_todo_list title: "Grocery list", description: "Food"

    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
John Stoveld
John Stoveld
4,203 Points

Hey Tim,

I am not quite as far as your code is.

I started posting this as soon as I got the error. and didn't continue.

Have restarted this twice. First time after I got the 28 errors.

Second after not being sure why I was getting 1 error. Continued as you suggested til the end of the referenced video and still getting the same error - twice for the same error code.

Im going to download the course zip file in a minute and try and run the server from there just to see what happens.

Back in 10.

John Stoveld
John Stoveld
4,203 Points

Commented out my code and dumped yours in there.

Same effect:

2 deprecation warnings total

Finished in 0.236 seconds
5 examples, 3 failures

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:84 # Creating todo lists displays an error when the todo list has no description
rspec ./spec/features/todo_lists/create_spec.rb:72 # Creating todo lists displays an error when the todo list has a title less than 3 characters
rspec ./spec/features/todo_lists/create_spec.rb:96 # Creating todo lists displays an error when the todo list has a description less than 5 characters.

Randomized with seed 61854

Sad face.

Tim Knight
Tim Knight
28,888 Points

Scroll up on your errors John, what are the errors that RSpec is providing you?

John Stoveld
John Stoveld
4,203 Points

Full output :

JSs-MacBook-Pro:odot JS$ bin/rspec spec/features/todo_lists/create_spec.rb
F.F.F

Failures:

  1) Creating todo lists displays an error when the todo list has a title less than 3 characters
     Failure/Error: expect(page).to have_content("error")
       expected to find text "error" in "Todo list was successfully created. Title: Hi Description: This is my todo list. Edit | Back"
     # ./spec/features/todo_lists/create_spec.rb:77:in `block (2 levels) in <top (required)>'

  2) Creating todo lists displays an error when the todo list has no description
     Failure/Error: expect(page).to have_content("error")
       expected to find text "error" in "Todo list was successfully created. Title: Grocery list Description: Edit | Back"
     # ./spec/features/todo_lists/create_spec.rb:89:in `block (2 levels) in <top (required)>'

  3) Creating todo lists displays an error when the todo list has a description less than 5 characters.
     Failure/Error: expect(page).to have_content("error")
       expected to find text "error" in "Todo list was successfully created. Title: Grocery list Description: Food Edit | Back"
     # ./spec/features/todo_lists/create_spec.rb:101:in `block (2 levels) in <top (required)>'

Deprecation Warnings:

--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:

  - rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
    now yield the example as a block argument, and that is the recommended
    way to access the current example from those contexts.
  - The current example is now exposed via `RSpec.current_example`,
    which is accessible from any context.
  - If you can't update the code at this call site (e.g. because it is in
    an extension gem), you can use this snippet to continue making this
    method available in RSpec 2.99 and RSpec 3:

      RSpec.configure do |c|
        c.expose_current_running_example_as :example
      end

(Called from /Users/JS/.rvm/gems/ruby-2.2.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:

  - rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
    now yield the example as a block argument, and that is the recommended
    way to access the current example from those contexts.
  - The current example is now exposed via `RSpec.current_example`,
    which is accessible from any context.
  - If you can't update the code at this call site (e.g. because it is in
    an extension gem), you can use this snippet to continue making this
    method available in RSpec 2.99 and RSpec 3:

      RSpec.configure do |c|
        c.expose_current_running_example_as :example
      end

(Called from /Users/JS/.rvm/gems/ruby-2.2.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:21:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

2 deprecation warnings total

Finished in 0.22363 seconds
5 examples, 3 failures

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:72 # Creating todo lists displays an error when the todo list has a title less than 3 characters
rspec ./spec/features/todo_lists/create_spec.rb:84 # Creating todo lists displays an error when the todo list has no description
rspec ./spec/features/todo_lists/create_spec.rb:96 # Creating todo lists displays an error when the todo list has a description less than 5 characters.

Randomized with seed 51974

And thank you by the way for your patience. Code babysitting has to be the worst.