Reputation: 401
surely I'm missing something... but what!?
in my spec I've
User.should_receive(:find).with("1").and_return(@user)
and in my controller
User.find(params[:id])
green light... correct...
but if I change my controller using another method, for example first:
User.first
or even
User.all
I get green light too... I was expecting an error like
expected: 1 time
received: 0 times
could anyone give me a hint to understand that behaviour?
many thanks
EDIT
here you could find more info about this issue: https://gist.github.com/3848429#file_user_controller_spec.rb
EDIT 2
my spec now, but I still need to check with method is calling each #find...
describe "GET #show" do
before(:each) do
@user = mock_model(User)
should_authorize(:show, @user)
end
it "assigns the requested user to @user" do
User.should_receive(:find).with("1").twice.and_return(@user)
get :show, id: "1"
end
it "renders the :show template" do
get :show, id: "1"
response.should render_template :show
end
end
Upvotes: 0
Views: 482
Reputation: 51697
I don't believe you need both User.stub!(:find)...
and User.should_receive(:find)...
since the should_receive basically acts like a stub. I would remove the first one and see if that that changes the behavior.
Upvotes: 1