Report abuse

categories_controller_spec.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe User::CategoriesController do

  describe "GET index" do
    it "assigns all categories as @categories" do
      mock_category = mock_model(Category)
      controller.should_receive(:current_user).and_return(mock_model(User,:categories => [mock_category]))
      get :index
      assigns[:categories].should == [mock_category]
    end
  end

end

categories_controller.rb

1
2
3
4
5
6
7
8
9
class User::CategoriesController < UserController
  def index
    @categories = current_user.categories

    respond_to do |format|
      format.html
    end
  end
end

rake spec:controllers output

1
2
3
4
5
6
7
8
9
10
11
12
/usr/bin/ruby1.8 /usr/lib/ruby/gems/1.8/gems/rspec-1.2.9/bin/spec --autospec spec/controllers/user/categories_controller_spec.rb -O spec/spec.opts
F

1)
'User::CategoriesController GET index assigns all categories as @categories' FAILED
expected: [#<Category:0x..fdbc41840 @name="Category_1001">],
     got: nil (using ==)
./spec/controllers/user/categories_controller_spec.rb:24:

Finished in 0.105629 seconds

1 example, 1 failure