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

Luis Castaneda
Luis Castaneda
4,160 Points

bin/rake spec - My TodoListsController.rb file does not look like the one on the video.

I get the following error:

Failure/Error: mock_todo_list.should_receive(:update).with({'these' => 'params'})
       Double "TodoList_1010" received :update with unexpected arguments
         expected: ({"these"=>"params"})
              got: ({})

my TodoListController.rb file looks like this:

require 'spec_helper'

describe TodoListsController do

  def mock_todo_list(stubs={})
    @mock_todo_list ||= mock_model(TodoList, stubs).as_null_object
  end

  describe "GET index" do
    it "assigns all todo_lists as @todo_lists" do
      TodoList.stub(:all) { [mock_todo_list] }
      get :index
      assigns(:todo_lists).should eq([mock_todo_list])
    end
  end

  describe "GET show" do
    it "assigns the requested todo_list as @todo_list" do
      TodoList.stub(:find).with("37") { mock_todo_list }
      get :show, :id => "37"
      assigns(:todo_list).should be(mock_todo_list)
    end
  end

  describe "GET new" do
    it "assigns a new todo_list as @todo_list" do
      TodoList.stub(:new) { mock_todo_list }
      get :new
      assigns(:todo_list).should be(mock_todo_list)
    end
  end

  describe "GET edit" do
    it "assigns the requested todo_list as @todo_list" do
      TodoList.stub(:find).with("37") { mock_todo_list }
      get :edit, :id => "37"
      assigns(:todo_list).should be(mock_todo_list)
    end
  end

  describe "POST create" do

    describe "with valid params" do
      it "assigns a newly created todo_list as @todo_list" do
        TodoList.stub(:new).with({'these' => 'params'}) { mock_todo_list(:save => true) }
        post :create, :todo_list => {'these' => 'params'}
        assigns(:todo_list).should be(mock_todo_list)
      end

      it "redirects to the created todo_list" do
        TodoList.stub(:new) { mock_todo_list(:save => true) }
        post :create, :todo_list => {}
        response.should redirect_to(todo_list_url(mock_todo_list))
      end
    end

    describe "with invalid params" do
      it "assigns a newly created but unsaved todo_list as @todo_list" do
        TodoList.stub(:new).with({'these' => 'params'}) { mock_todo_list(:save => false) }
        post :create, :todo_list => {'these' => 'params'}
        assigns(:todo_list).should be(mock_todo_list)
      end

      it "re-renders the 'new' template" do
        TodoList.stub(:new) { mock_todo_list(:save => false) }
        post :create, :todo_list => {}
        response.should render_template("new")
      end
    end

  end

  describe "PUT update" do

    describe "with valid params" do
      it "updates the requested todo_list" do
        TodoList.should_receive(:find).with("37") { mock_todo_list }
        mock_todo_list.should_receive(:update).with({'these' => 'params'})
        put :update, :id => "37", :todo_list => {'these' => 'params'}
      end

      it "assigns the requested todo_list as @todo_list" do
        TodoList.stub(:find) { mock_todo_list(:update => true) }
        put :update, :id => "1"
        assigns(:todo_list).should be(mock_todo_list)
      end

      it "redirects to the todo_list" do
        TodoList.stub(:find) { mock_todo_list(:update => true) }
        put :update, :id => "1"
        response.should redirect_to(todo_list_url(mock_todo_list))
      end
    end

    describe "with invalid params" do
      it "assigns the todo_list as @todo_list" do
        TodoList.stub(:find) { mock_todo_list(:update => false) }
        put :update, :id => "1"
        assigns(:todo_list).should be(mock_todo_list)
      end

      it "re-renders the 'edit' template" do
        TodoList.stub(:find) { mock_todo_list(:update => false) }
        put :update, :id => "1"
        response.should render_template("edit")
      end
    end

  end

  describe "DELETE destroy" do
    it "destroys the requested todo_list" do
      TodoList.should_receive(:find).with("37") { mock_todo_list }
      mock_todo_list.should_receive(:destroy)
      delete :destroy, :id => "37"
    end

    it "redirects to the todo_lists list" do
      TodoList.stub(:find) { mock_todo_list }
      delete :destroy, :id => "1"
      response.should redirect_to(todo_lists_url)
    end
  end

end

I'm using rspec v 2.99.2

Can someone tell me what to edit to get the bin/rake spec command working?

1 Answer

Nathan Elliott
Nathan Elliott
16,232 Points

Hello Luis,

In your application, you named the controller spec something ending in _spec.rb rather than naming it ToDoListController.rb right? If you accidentally filled out your controller with what you meant to be in your controller spec, you will need to go back and correct that.

Luis Castaneda
Luis Castaneda
4,160 Points

Thanks Nathan. I figured out that I missed one of the configurations at the beginning of the course. I have rebuild it from the start and found what I have done wrong.