[rspec-users] mock_model

Ashley Moran ashley.moran at patchspace.co.uk
Thu Apr 10 18:04:31 EDT 2008

On 10 Apr 2008, at 22:28, David Chelimsky wrote:
> Not sure what you mean here - that is handled transparently by
> stub_model so you don't have to make any such distinction. Take a look
> at http://github.com/dchelimsky/rspec-rails/tree/master/lib/spec/rails/example/rails_example_group.rb
> and see if it sheds some light.

So it does - the code in the previous post was this, however:

   stub_model(Person, :attrs => {:last_name => 'Name'},
     :stubs => {:full_name => 'Full Name'})

Where did :attrs and :stubs go?  (or come from?)

>> I have to say, though, I don't see
>> the advantage of using a real object as the basis for the mock as  
>> long
>> as one is used as a sanity check for the stubs (maybe I am missing a
>> benefit).
> Not sure what you mean here either. Can you elaborate?

Just that you have the line
  model_class.new do |model|

Where I did

then later when stubbing did something like
   stubs.each { |msg, ret|
         ... raise unless model_class.new.respond_to?(msg) }

This gives you the advantage of checking the stubs against a real  
model but on a "pure" mock.  I just wasn't sure what the advantage of  
using a partial mock was, in this case.

As for the comment:
>         #--
>         # TODO - Shouldn't this just be an extension of stub! ??
>         # - object.stub!(:method => return_value, :method2 =>  
> return_value2, :etc => etc)
>         #++

+1 on that too.  I've wanted that for so long :D



More information about the rspec-users mailing list