title: Rspec error - NoMethodError: undefined method `empty?'
body: <p>I'm now making Rspec for controller <code>SearchController</code>. This controller do search record by sql with parameter which was got by "get" request. The controller is as follow. </p>
  
  <pre><code>class SearchController &lt; ApplicationController
  
    def index
      if params[:category] == 'All'
        @search_result = Item.find_by_sql("SELECT * FROM items WHERE name LIKE '%# {params[:name]}%'")
      else
        @search_result = Item.find_by_sql("SELECT * FROM items WHERE name LIKE '%#{params[:name]}%' AND category = '#{params[:category]}'")
      end
      if @search_result.empty? then
        redirect_to main_app.root_path, notice: "No items found matching your search criteria ! Modify your search."
      else
        @search_result=@search_result.paginate(:page =&gt; params[:page],:per_page =&gt; 3)
      end
    end
   end
  </code></pre>
  
  <p>Then I wrote simple Rspec test as follow. This test intends that at first the object <code>item</code> is made to use in controller. Also the stub (<code>Item.stub(:find_by_sql).and_return(item)</code>) is declared. Then do <code>get :index</code> with parameter <code>:category =&gt; 'All'</code>. My expect is that in the controller <code>if params[:category] == 'All'</code> is passed and <code>@search_result</code> is filled by object. (As I mentioned, the stub was already declared. Also object was already made. Then <code>Item.find_by_sql(*****)</code> would return object which was already declared.)</p>
  
  <pre><code>require 'spec_helper'
  
  describe SearchController do
  
    let(:valid_session) { {} }
  
    describe "" do
       it "" do
        item = Item.new(auction_id:'1',min_bid_price:'100.0')
        item.save
        Item.stub(:find_by_sql).and_return(item)
  
        get :index, {:category =&gt; 'All'}, valid_session
  
        @search_result.should_not be_empty
  
       end
    end
  end
  </code></pre>
  
  <p>Then I ran Rspec and unfortunately got the error as follow. I think <code>@search_result</code> could not be successfully filled with object, so "empty?" could not be called. However I have no idea about how to fix this. I already use many hours about this. I would like to have someone's help.</p>
  
  <pre><code>Failures:
  
    1) SearchController
       Failure/Error: get :index, {:category =&gt; 'All'}, valid_session
       NoMethodError:
       undefined method `empty?' for #&lt;Item:0x523c980&gt;
       # ./app/controllers/search_controller.rb:9:in `index'
       # ./spec/controllers/search_controller_spec.rb:13:in `block (3 levels) in &lt;top (required)&gt;'
  
       Finished in 0.25 seconds
       1 example, 1 failure
  
    Failed examples:
  
       rspec ./spec/controllers/search_controller_spec.rb:8 # SearchController
  
       Randomized with seed 50151 
  </code></pre>