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?
msan
May 7, 2011, 7:17pm
2
get :search, :name => @name
and in controller data_search is expected to be present.
2011/5/7 Mauro [email protected]
msan
May 7, 2011, 7:26pm
3
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.
msan
May 7, 2011, 8:36pm
4
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
msan
May 7, 2011, 11:06pm
5
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?
msan
May 7, 2011, 11:12pm
6
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.