[rspec-users] Stubbing calls to the command line

Andy Croll lists at ruby-forum.com
Thu Aug 14 23:58:35 EDT 2008


Scott Taylor wrote:
> Use Kernel.stub!(:`, "wget..."), and use Kernel.send(:`, "wget")
> instead of literal backticks.

Interestingly this doesn't quite work, but I used the principle.

The Kernel module is mixed into Object so when you use `shellcommand... 
` you can intercept the call on the object itself.

So I was able to:

@my_obj.stub!(:`)   ...in the before block

and

@my_obj.should_receive(:`, "wget...")   ...in the test

and use the short form:

`wget... `   ...in the actual method.

Thanks for your help chaps.
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list