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 Deleting Todo Lists

John Stoveld
John Stoveld
4,203 Points

Errors upon rake

Adventures in troubleshooting.

After a colossal fail with my spelling error earlier I now have the next item on my laundry list.

The following command :

bin/rake spec

spits out the following errors I am about to post.

Before you tell me what I need to do. I need to start learning to crawl before I can start jogging.

What do these errors mean? I figured out that the errors link to to the files and the line of code. What gets me is what is it telling me to fix?

JSs-MacBook-Pro:odot JS$ bin/rake spec
/Users/JS/.rvm/rubies/ruby-2.2.0/bin/ruby -S rspec ./spec/controllers/todo_lists_controller_spec.rb ./spec/features/todo_lists/create_spec.rb ./spec/features/todo_lists/destroy_spec.rb ./spec/features/todo_lists/edit_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
DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in <top (required)> at /Users/JS/Documents/Projects/odot/config/environments/test.rb:16)
*........FFFFDEPRECATION WARNING: `named_routes.helpers` is deprecated, please use `route_defined?(route_name)` to see if a named route was defined. (called from block (4 levels) in <top (required)> at /Users/JS/Documents/Projects/odot/spec/controllers/todo_lists_controller_spec.rb:75)
FF...FFFFFFF..............*.

Pending:
  TodoListsHelper add some examples to (or delete) /Users/JS/Documents/Projects/odot/spec/helpers/todo_lists_helper_spec.rb
    # No reason given
    # ./spec/helpers/todo_lists_helper_spec.rb:14
  TodoList add some examples to (or delete) /Users/JS/Documents/Projects/odot/spec/models/todo_list_spec.rb
    # No reason given
    # ./spec/models/todo_list_spec.rb:4

Failures:

  1) TodoListsController DELETE destroy destroys the requested todo_list
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:147:in `block (3 levels) in <top (required)>'

  2) TodoListsController DELETE destroy redirects to the todo_lists list
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:154:in `block (3 levels) in <top (required)>'

  3) TodoListsController GET edit assigns the requested todo_list as @todo_list
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:58:in `block (3 levels) in <top (required)>'

  4) TodoListsController POST create with valid params creates a new TodoList
     Failure/Error: expect {
       count should have been changed by 1, but was changed by 0
     # ./spec/controllers/todo_lists_controller_spec.rb:67:in `block (4 levels) in <top (required)>'

  5) TodoListsController POST create with valid params assigns a newly created todo_list as @todo_list
     Failure/Error: assigns(:todo_list).should be_persisted
       expected persisted? to return true, got false
     # ./spec/controllers/todo_lists_controller_spec.rb:75:in `block (4 levels) in <top (required)>'

  6) TodoListsController POST create with valid params redirects to the created todo_list
     Failure/Error: response.should redirect_to(TodoList.last)
       Expected response to be a <redirect>, but was <200>
     # ./spec/controllers/todo_lists_controller_spec.rb:80:in `block (4 levels) in <top (required)>'

  7) TodoListsController GET show assigns the requested todo_list as @todo_list
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:43:in `block (3 levels) in <top (required)>'

  8) TodoListsController PUT update with valid params updates the requested todo_list
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:104:in `block (4 levels) in <top (required)>'

  9) TodoListsController PUT update with valid params assigns the requested todo_list as @todo_list
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:114:in `block (4 levels) in <top (required)>'

  10) TodoListsController PUT update with valid params redirects to the todo_list
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:120:in `block (4 levels) in <top (required)>'

  11) TodoListsController PUT update with invalid params assigns the todo_list as @todo_list
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:128:in `block (4 levels) in <top (required)>'

  12) TodoListsController PUT update with invalid params re-renders the 'edit' template
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:136:in `block (4 levels) in <top (required)>'

  13) TodoListsController GET index assigns all todo_lists as @todo_lists
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:35:in `block (3 levels) in <top (required)>'

Next we have the warnings

I believe these are due to version updates and warnings of code malfunctioning in the future?

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)>')
--------------------------------------------------------------------------------

`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from /Users/JS/Documents/Projects/odot/spec/views/todo_lists/new.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from /Users/JS/Documents/Projects/odot/spec/views/todo_lists/edit.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from /Users/JS/Documents/Projects/odot/spec/views/todo_lists/show.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
Too many uses of deprecated '`stub_model`'. Pass `--deprecation-out` or set `config.deprecation_stream` to a file for full output.

--------------------------------------------------------------------------------
rspec-rails 3 will no longer automatically infer an example group's spec type
from the file location. You can explicitly opt-in to this feature using this
snippet:

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!
end

If you wish to manually label spec types via metadata you can safely ignore
this warning and continue upgrading to RSpec 3 without addressing it.
--------------------------------------------------------------------------------

Clearly the below are the errors - though it looks like it makes sense, I just dont know what needs to be changed.

Finished in 0.62342 seconds
41 examples, 13 failures, 2 pending

Failed examples:

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/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:42 # TodoListsController GET show assigns the requested todo_list as @todo_list
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:34 # TodoListsController GET index assigns all todo_lists as @todo_lists

Randomized with seed 16979

/Users/JS/.rvm/rubies/ruby-2.2.0/bin/ruby -S rspec ./spec/controllers/todo_lists_controller_spec.rb ./spec/features/todo_lists/create_spec.rb ./spec/features/todo_lists/destroy_spec.rb ./spec/features/todo_lists/edit_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

3 Answers

Brandon Barrette
Brandon Barrette
20,485 Points

I'll walk you through the first error... after that you'll have to ask more specific questions.

1) TodoListsController DELETE destroy destroys the requested todo_list
     Failure/Error: todo_list = TodoList.create! valid_attributes
     ActiveRecord::UnknownAttributeError:
       unknown attribute 'Description' for TodoList.
     # ./spec/controllers/todo_lists_controller_spec.rb:147:in `block (3 levels) in <top (required)>'

The last line tells you where the error is:

 # ./spec/controllers/todo_lists_controller_spec.rb:147:in `block (3 levels) in <top (required)>'

So it's in your todo_lists_controller spec on line 147. Then look above that line, it tells you what's wrong:

unknown attribute 'Description' for TodoList.

Without seeing your todo_list_controller_spec, I can only speculate what's wrong. But my guess is only 1 line of code is causing most of these errors (because notice each failure says "unknown attribute 'Description' for TodoList.") This means it is happening in one place that every test uses. My guess is the valid_attributes at the top of the page. I have a feeling it looks something like this:

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

When it should really be lowercase (all keys should be lowercase to match with the database)

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

Hope that helps! Happy coding =)

John Stoveld
John Stoveld
4,203 Points

Hey Brandon -

Didnt see this til Just now. Ill look at all of this today around 6est. Thanks for taking the time to point this all out.

John Stoveld
John Stoveld
4,203 Points

Frustration up the wazoo.

Just tried to go back to the project after not touching it for a while. rails server command now dies:

JSs-MacBook-Pro:odot JS$ rails server
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/JS/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load': /Users/JS/Documents/Projects/odot/config/routes.rb:61: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)

Im baffled.

If youd like to look at what I have for code its hosted here:

https://github.com/jstoveld/odot

What a pain in the butt.

John Stoveld
John Stoveld
4,203 Points

So Im still getting a series of errors on this.

Re bundled and what not - and this is what my todo_lists_controller_spec looks like (Please note the S on the end... would this be my issue?)

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

  describe "GET show" do
    it "assigns the requested todo_list as @todo_list" do
      todo_list = TodoList.create! valid_attributes
      get :show, {:id => todo_list.to_param}, valid_session
      assigns(:todo_list).should eq(todo_list)
    end
  end

  describe "GET new" do
    it "assigns a new todo_list as @todo_list" do
      get :new, {}, valid_session
      assigns(:todo_list).should be_a_new(TodoList)
    end
  end

  describe "GET edit" do
    it "assigns the requested todo_list as @todo_list" do
      todo_list = TodoList.create! valid_attributes
      get :edit, {:id => todo_list.to_param}, valid_session
      assigns(:todo_list).should eq(todo_list)
    end
  end

  describe "POST create" do
    describe "with valid params" do
      it "creates a new TodoList" do
        expect {
          post :create, {:todo_list => valid_attributes}, valid_session
        }.to change(TodoList, :count).by(1)
      end

      it "assigns a newly created todo_list as @todo_list" do
        post :create, {:todo_list => valid_attributes}, valid_session
        assigns(:todo_list).should be_a(TodoList)
        assigns(:todo_list).should be_persisted
      end

      it "redirects to the created todo_list" do
        post :create, {:todo_list => valid_attributes}, valid_session
        response.should redirect_to(TodoList.last)
      end
    end

    describe "with invalid params" do
      it "assigns a newly created but unsaved todo_list as @todo_list" do
        # Trigger the behavior that occurs when invalid params are submitted
        TodoList.any_instance.stub(:save).and_return(false)
        post :create, {:todo_list => { "title" => "invalid value" }}, valid_session
        assigns(:todo_list).should be_a_new(TodoList)
      end

      it "re-renders the 'new' template" do
        # Trigger the behavior that occurs when invalid params are submitted
        TodoList.any_instance.stub(:save).and_return(false)
        post :create, {:todo_list => { "title" => "invalid value" }}, valid_session
        response.should render_template("new")
      end
    end
  end

  describe "PUT update" do
    describe "with valid params" do
      it "updates the requested todo_list" do
        todo_list = TodoList.create! valid_attributes
        # Assuming there are no other todo_lists in the database, this
        # specifies that the TodoList created on the previous line
        # receives the :update_attributes message with whatever params are
        # submitted in the request.
        TodoList.any_instance.should_receive(:update).with({ "title" => "MyString" })
        put :update, {:id => todo_list.to_param, :todo_list => { "title" => "MyString" }}, valid_session
      end

      it "assigns the requested todo_list as @todo_list" do
        todo_list = TodoList.create! valid_attributes
        put :update, {:id => todo_list.to_param, :todo_list => valid_attributes}, valid_session
        assigns(:todo_list).should eq(todo_list)
      end

      it "redirects to the todo_list" do
        todo_list = TodoList.create! valid_attributes
        put :update, {:id => todo_list.to_param, :todo_list => valid_attributes}, valid_session
        response.should redirect_to(todo_list)
      end
    end

    describe "with invalid params" do
      it "assigns the todo_list as @todo_list" do
        todo_list = TodoList.create! valid_attributes
        # Trigger the behavior that occurs when invalid params are submitted
        TodoList.any_instance.stub(:save).and_return(false)
        put :update, {:id => todo_list.to_param, :todo_list => { "title" => "invalid value" }}, valid_session
        assigns(:todo_list).should eq(todo_list)
      end

      it "re-renders the 'edit' template" do
        todo_list = TodoList.create! valid_attributes
        # Trigger the behavior that occurs when invalid params are submitted
        TodoList.any_instance.stub(:save).and_return(false)
        put :update, {:id => todo_list.to_param, :todo_list => { "title" => "invalid value" }}, valid_session
        response.should render_template("edit")
      end
    end
  end

  describe "DELETE destroy" do
    it "destroys the requested todo_list" do
      todo_list = TodoList.create! valid_attributes
      expect {
        delete :destroy, {:id => todo_list.to_param}, valid_session
      }.to change(TodoList, :count).by(-1)
    end

    it "redirects to the todo_lists list" do
      todo_list = TodoList.create! valid_attributes
      delete :destroy, {:id => todo_list.to_param}, valid_session
      response.should redirect_to(todo_lists_url)
    end
  end

end

'''

So I am still perplexed.
Brandon Barrette
Brandon Barrette
20,485 Points

Ok, so what's happened is you are using the newest version of Rails (4.2.0) but using the old version of Rspec (2.0). Rails 4.2 requires Rspec 3.1

So here's what you are going to do. Go to your Gemfile and change the following and add a new gem:

gem 'rails', '4.1.8'

# development, test
gem 'rspec-rails', '~> 2.9'
gem 'rspec-activemodel-mocks' # THIS ONE IS NEW

# test
gem 'capybara', '~> 2.1.0'

Then run

   bundle update

Then run your bin/rspec.. You will still get some depreciation warnings. Read them, and follow the instructions to change your spec_helper.rb file and they will go away. Open a new forum discussion if you have questions about those depreciations.

Thank you Brandon Barrete, i spent like 5 hours trying to solve my tests failures when bin/rake spec. Finally i followed your instructions and it all worked!

Thanx!