[rspec-users] Mock_model not recognizing act_as_mappable

Steve Loo isignin at gmail.com
Fri Aug 3 13:33:07 UTC 2012


I am using mock_model in my tests, and I encountered a situation where my
stub is failing. Here's the scenario:

Controller:

   @locations = Location.al(:bounds=>bounds)l

   @locations.sort_by_distance_from([bounds.center.lat,bounds.center.lng])


Rspec:

 @location = mock_model(Location)

 Location.stub(:all).and_return([@location])

 @location.stub!(:sort_by_distance_from).and_return([@location])


Within real model: Location

   act_as_mappable

   ....


the :sort_by_distance_from  is a method from within act_as_mappable.

Upon investigation, when I compare the available methods for both the
Location model and the mock_model, I found act_as_mappable is missing from
the mock_model.

Which accounts for why it was failing in the
stub @location.stub!(:sort_by_distance_from). It gives an error "unexpected
message :distance_to" and the :distance_to method comes from
act_as_mappable.


When I switch to using Factory for the @location instance, the test passed.

How should I go about using the mock_model for a situation as this, without
resorting to using Factory? I believe this issue also the same for other
act_as_ situations because I also noted that a number of my act_as.. are
not available in the mock_model as they are in the actual model.


Thanks for the help

Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120803/50acf9ed/attachment.html>


More information about the rspec-users mailing list