[rspec-users] mocking/stubbing newbie questions
Scott Taylor
scotttaylor at bigfoot.com
Tue Mar 27 09:55:06 EDT 2007
I'm new to mocking and stubbing. Can someone help me out with the
following? I don't exactly know why this spec is failing:
describe "GET /users/1/terms" do
controller_name :terms
setup do
@user = mock_model(User)
User.stub!(:find).and_return(@user)
end
def do_get
get :index, :user_id => 1
end
it "should find all terms associated with the user" do
User.should_receive(:find).with("1")
end
end
the controller code:
class TermsController < ApplicationController
def index
User.find(1)
end
end
the spec results:
1)
Spec::Mocks::MockExpectationError in 'GET /users/1/terms should find
all terms associated with the user'
User expected :find with ("1") once, but received it 0 times
./spec/controllers/terms_controller_spec.rb:43:
./script/rails_spec_server:21:in `run'
./script/rails_spec_server:42:
Thanks for any help in advance,
Scott
More information about the rspec-users
mailing list