Hi friends
I am new to rspec. i have one doubt about show action
for example [1] ---->If we use the below way i.e get :show,:id => 1 above the query i got error.
"Spec::Mocks::MockExpectationError in 'MyController GET show should find my controller and return object ' expected :find_by_id with ("1") once, but received it 0 times"
describe MyControler, "GET show" do before(:each) do @user = Factory(:complete_user) controller.stub!(:require_user => true , :current_user => @user) @my_controller = mock_model(MyControler) @user.my_controllers.stub!(:find_by_id).and_return @my_controller end
it "should find my controller and return object " do get :show,:id => 1 @user.my_controllers.should_receive(:find_by_id).with('1').and_return(@my_controller) end end
[2] :but if i use get :show,:id => 1 below the query like
it "should find my controller and return object " do @user.my_controllers.should_receive(:find_by_id).with('1').and_return(@my_controller) get :show,:id => 1 end
i am not getting any error.
Why? What is the reason? Could any one explain please?