Hello, 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() vehical1.stubs(:mph).returns(150) vehical2.stubs(:mph).returns(250) comparer.add_vehical([@vehical1, @vehical2]) comparer.sort_by(:mph) 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] } end 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 -- Chris Lowis http://www.chrislowis.co.uk/
I think you''re meaning to do vehical1.stubs(:[]).with(;mph).returns(150) vehical2.stubs(:[]).with(;mph).returns(250) Or in your prod code write vehicle.send(:mph) instead of vehical[symb] Also in your test you should probably be doing comparer.add_vehical ([vehical1, vehical2]) instead of @vehical1, @vehical2 Hope that helps. -Zach On Sep 5, 2007, at 5:04 PM, Chris Lowis wrote:> Hello, > > 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() > vehical1.stubs(:mph).returns(150) > vehical2.stubs(:mph).returns(250) > comparer.add_vehical([@vehical1, @vehical2]) > comparer.sort_by(:mph) > > 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] } > end > > 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 > > > > > > > > > > -- > Chris Lowis > http://www.chrislowis.co.uk/ > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer
Doh typo, that was vehical.send(symb) not vehical.send(:mph) (Vehicle vs Vehical threw me off a bit) -Zach On Sep 5, 2007, at 5:40 PM, Zach Moazeni wrote:> I think you''re meaning to do > > vehical1.stubs(:[]).with(;mph).returns(150) > vehical2.stubs(:[]).with(;mph).returns(250) > > Or in your prod code write vehicle.send(:mph) instead of vehical[symb] > > Also in your test you should probably be doing comparer.add_vehical > ([vehical1, vehical2]) instead of @vehical1, @vehical2 > > Hope that helps. > > -Zach > > On Sep 5, 2007, at 5:04 PM, Chris Lowis wrote: > >> Hello, >> >> 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() >> vehical1.stubs(:mph).returns(150) >> vehical2.stubs(:mph).returns(250) >> comparer.add_vehical([@vehical1, @vehical2]) >> comparer.sort_by(:mph) >> >> 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] } >> end >> >> 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 >> >> >> >> >> >> >> >> >> >> -- >> Chris Lowis >> http://www.chrislowis.co.uk/ >> _______________________________________________ >> mocha-developer mailing list >> mocha-developer at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mocha-developer >
Doh typo, that was vehical.send(symb) not vehical.send(:mph) (Vehicle vs Vehical threw me off a bit) -Zach On Sep 5, 2007, at 5:40 PM, Zach Moazeni wrote:> I think you''re meaning to do > > vehical1.stubs(:[]).with(;mph).returns(150) > vehical2.stubs(:[]).with(;mph).returns(250) > > Or in your prod code write vehicle.send(:mph) instead of vehical[symb] > > Also in your test you should probably be doing comparer.add_vehical > ([vehical1, vehical2]) instead of @vehical1, @vehical2 > > Hope that helps. > > -Zach > > On Sep 5, 2007, at 5:04 PM, Chris Lowis wrote: > >> Hello, >> >> 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() >> vehical1.stubs(:mph).returns(150) >> vehical2.stubs(:mph).returns(250) >> comparer.add_vehical([@vehical1, @vehical2]) >> comparer.sort_by(:mph) >> >> 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] } >> end >> >> 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 >> >> >> >> >> >> >> >> >> >> -- >> Chris Lowis >> http://www.chrislowis.co.uk/ >> _______________________________________________ >> mocha-developer mailing list >> mocha-developer at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mocha-developer >