Rspec what I'm doing wrong?

In controller I have:

def search
unless params[:data_search].blank?
shop_data = params[:data_search]
@shops = Shop.data_search(shop_data).paginate(:per_page =>
Settings.shops_per_page, :page => params[:page])
else
@shops = Shop.all.paginate(:per_page => Settings.shops_per_page,
:page => params[:page])
end
render :layout => false if request.xhr?
end

In controller.spec I have:

def mock_shop(stubs={})
@mock_shop ||= mock_model(Shop, stubs).as_null_object
end

describe “search” do
context “when name is ‘Test’” do
it “should find shops” do
@name = “Test”
Shop.stub(:search).with(@name) { [mock_shop] }
get :search, :name => @name
assigns(:shops).should eq([mock_shop])
end
end
end

The failure is:

Failure/Error: assigns(:shops).should eq([mock_shop])

   expected [#<Shop:0x9f4 @name="Shop_1032">]
        got []

   (compared using ==)

   Diff:
   @@ -1,2 +1,2 @@
   -[#<Shop:0x9f4 @name="Shop_1032">]
   +[]

What I am doing wrong?

get :search, :name => @name

and in controller data_search is expected to be present.

2011/5/7 Mauro [email protected]

On 7 May 2011 19:16, Gintautas Šimkus [email protected] wrote:

get :search, :name => @name

and in controller data_search is expected to be present.

Yes, parameter is wrong but putting get :search, :data_search => @name
I have the same failure.

On 7 May 2011, at 18:08, Mauro [email protected] wrote:

  Diff:
  @@ -1,2 +1,2 @@
  -[#<Shop:0x9f4 @name="Shop_1032">]
  +[]

What I am doing wrong?

It doesn’t look like you’re calling the stubbed method

Fred

On 7 May 2011 20:35, Frederick C. [email protected]
wrote:

assigns(:shops).should eq([mock_shop])
got []
It doesn’t look like you’re calling the stubbed method
Can you suggest how can I solve?

On 7 May 2011 23:05, Mauro [email protected] wrote:

get :search, :name => @name
expected [#<Shop:0x9f4 @name=“Shop_1032”>]

It doesn’t look like you’re calling the stubbed method

Can you suggest how can I solve?

Sorry I’ve solved the error was Shop.stub(:search), it must be
Shop.stub(:data_search) sorry for the noise.