[mocha-developer] Mocking system/`

jpywtora at calpoly.edu jpywtora at calpoly.edu
Tue Jun 12 01:18:04 EDT 2007


Great; However, I was hoping to see how to mock the backtics, any ideas?

Object.any_instance.expects(:`).with("ls")   # my guess, but is wrong

Thanks

--- Original Message ---
> Bah, turned out to be a Merb reloading bug. Nevermind.
> 
> On 6/11/07, Frederick Cheung <fred at 82ask.com> wrote:
> >
> > On 11 Jun 2007, at 23:19, Kevin Clark wrote:
> >
> > > This drives me insane on a regular basis. How does one mock
> > > system('blah') or `blah` ?
> > >
> > > Adding expectations on Kernel doesn't do it. Adding expectations on
> > > Object just makes me sad:
> > >
> > > Object.any_instance.expects(:system).with('ls')
> > >   # => #<Mock:0x12b584e>.system('ls') - expected calls: 0, actual
> > > calls: 1
> > >
> > > And this really shouldn't work (and doesn't):
> > >
> > > Object.expects(:system).with('ls')
> > >   # => #<Mock:0x12f287a>.system('ls') - expected calls: 1, actual
> > > calls: 0
> > >
> > > Anyone have a trick they like?
> >
> > system etc... are in a module that is included most places, so if we
> > have
> >
> > class Foo
> >    def my_method_calling_system
> >      system('echo "hello world"')
> >    end
> > end
> >
> > Then you need to do something like
> >
> > f = Foo.new
> > f.expects(:system).
> > f.my_method_calling_system
> >
> >
> > I would have expected Object.any_instance.expects(:system) to work
> > but a cursory attempt suggests it doesn;t
> >
> > Fred
> >
> >
> >
> >
> >
> > _______________________________________________
> > mocha-developer mailing list
> > mocha-developer at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/mocha-developer
> >
> 
> 
> -- 
> Kevin Clark
> http://glu.ttono.us
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer



More information about the mocha-developer mailing list