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
On 27/03/2007, at 11:55 PM, Scott Taylor wrote:> it "should find all terms associated with the user" do > User.should_receive(:find).with("1") > end > end...> 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:you forgot to actually call your do_get method: it "should find all terms associated with the user" do User.should_receive(:find).with("1") do_get end -- tim
What a dumb move. I need to sleep more. Thanks for your help. Scott On Mar 27, 2007, at 10:01 AM, Tim Lucas wrote:> On 27/03/2007, at 11:55 PM, Scott Taylor wrote: > >> it "should find all terms associated with the user" do >> User.should_receive(:find).with("1") >> end >> end > > ... > >> 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: > > you forgot to actually call your do_get method: > > it "should find all terms associated with the user" do > User.should_receive(:find).with("1") > do_get > end > > -- tim > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users