[Rspec-users] Creating a 'default' mock

Chris Roos chrisjroos at gmail.com
Tue Jul 25 07:31:52 EDT 2006


On 7/24/06, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> On 7/24/06, Chris Roos <chrisjroos at gmail.com> wrote:
> > Am I correct in thinking that it's not currently possible to have a
> > method that creates a 'standard' mock (i.e. a mock that has defaults
> > useful in all contexts)?
> >
>
> It should be possible to do that. Can you be more specific about what
> you mean by defaults?
>
Although I don't currently need this anymore...  I was wanting a way
to create a mock object that responded in certain ways to some stock
messages.  I then wanted to be able to use this mock in each of my
different contexts by customising it with expectations.

> > I've tried with the mock method and also by manually creating new Mock
> > instances.  I get failures when setting up expectations (undefined
> > method 'receive' for proc).
> >
>
> Please provide some code so we can see what you're trying to do.
> Also, which version of RSpec are you using?
>
Version 0.5.15.  I was doing something like...

def mock_row
 row = mock('row')
 row.expects(:foo).returns('bar')
 row
end

... and then trying to re-use it in my context set-ups.  This is where I
got the error stated in the original email.

The reason that this is no longer required is because I realised the
way to ensure that message _are not_ received (receive(:foo).never).
This allows me to set my mocks as null_objects and remove lots of the
duplication that I was trying to solve with this 'default mock'

Cheers,

Chris

> > Chris
> > _______________________________________________
> > 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
>


More information about the Rspec-users mailing list