[rspec-users] how to mock/stub when there are multiple model objects?

David Chelimsky dchelimsky at gmail.com
Mon Jun 27 06:50:57 EDT 2011


On Jun 23, 2011, at 3:55 PM, S Ahmed wrote:

> Thanks.
> 
> I'm trying this now on a Model that is using Mongoid.
> 
> I have tried:
> 
> it "should ..." do
> 
>    User.stub(:some_call).and_return(User.new(:name => "blah"))
> 
> end
> 
> And when running spec on this file I get:
> 
> NoMethodError, undefined method "stub" for User:Class
> 
> I also tried:
> 
> User.stub!(:some_call)....
> 
> Does this not work on mongoid objects?

It should work on any object (class objects and instance objects), so it sounds like there is a configuration problem. What's in your Gemfile?

> 
> On Fri, Jun 17, 2011 at 7:39 PM, Patrick J. Collins <patrick at collinatorstudios.com> wrote:
> > but what if my method looks like:
> >
> >    user = User.where("...")
> >    user2 = User.where("...")
> User.should_receive(:where).with("...").and_return(...)
> http://apidock.com/rspec/Spec/Mocks
> 
> Patrick J. Collins
> http://collinatorstudios.com
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
> 
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

Cheers,
David



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110627/6232c353/attachment-0001.html>


More information about the rspec-users mailing list