[mocha-developer] Mocking to spec a sort_by method

Chris Lowis chris at chrislowis.co.uk
Wed Sep 5 17:04:16 EDT 2007


I have a question regarding the use of Mocha with rSpec to spec one of
my methods.

My spec contains the following

vehical1 = mock()
vehical2 = mock()
comparer.add_vehical([@vehical1, @vehical2])

The comparer is an object that has a basic "stack like" functionality,
add_vehical is the method to add objects to the stack.

My sort_by method in the comparer class looks like

def sort_by(symb)
    @vehicals.sort_by{|vehical| vehical[symb] }

where @vehicals is an instance variable array (the stack).

Running my spec gives the following error,

Mocha::ExpectationError in 'Comparer should be sortable on a specific symbol'
#<Mock:0x251b7c8>.[](:mph) - expected calls: 0, actual calls: 1

I assume sort_by is trying to call a [] method ? How do I stub this
method correctly using Mocha ?

Thank you for any help,


Chris Lowis

More information about the mocha-developer mailing list