[rspec-users] Help me with Controllers spec

Elza elza.morelli at tagview.com.br
Fri Oct 16 00:25:46 EDT 2009


I am starting with Rspec and I am having some errors in the Get/index
Can someone help me with this?

describe BrandsController, 'GET /index' do
  ##############################################################
  should_require_login :get, :index    
  ##############################################################
  describe "authenticated user" do     
    ##############################################################
    before do
      login_as_user 
      @brands = mock_model(Brand)
      @brands.stub!(:paginate).and_return(@brands) 
    end
    ##############################################################
    def do_get
      get :index
    end
    
    ##############################################################
    it 'should load the brands' do
      @brands.should_receive(:paginate).with(
        :conditions => {:active => 'true'},
        :order =>'brands.name'
      ).and_return(@brands) 
      
      do_get
      
      assigns[:brands].should == @brands 
    end
  end  
end
************************************
My controller is
  def index
    # Build the SQL conditions object based on the parameters received.
    conditions = Sql::Conditions.new
    conditions.and('name LIKE ?', "%#{get_param(:name)}%")  if
get_param(:name)
    conditions.and('active = ?', true)                                      
if !get_param(:include_inactive, :boolean)

    @brands = 
        Brand.paginate(
          :conditions => conditions.to_sql,
          :order      => build_sort_conditions(:name, true),
          :page       => get_param(:page, :integer),
          :per_page   => 10
        )
  end
 ************************************************

The error is 

'BrandsController GET /index authenticated user should load the brands'
FAILED
expected: #<Brand:0xfd2e56 @name="Brand_1058">,
     got: [] (using ==)
-- 
View this message in context: http://www.nabble.com/Help-me-with-Controllers-spec-tp25919605p25919605.html
Sent from the rspec-users mailing list archive at Nabble.com.



More information about the rspec-users mailing list