[rspec-users] Stubbing a Kernel method?

Ashley Moran work at ashleymoran.me.uk
Sat Oct 20 05:02:04 EDT 2007


On Oct 19, 2007, at 5:18 pm, Paul Dlug wrote:

> Kernel.should_receive(:open).with('filename').and_return('data')

Had this exact same issue with OpenURI myself two days ago.  The  
other replies are better OO but the quickest way it to use the  
OpenURI.open_uri class method, which you can stub out without  
interfering with Kernel.  (Unless you want it to handle files as well  
as URLs that is.)

BTW I have no idea what the OpenURI.open_uri method is all about, as  
open-uri's wrapper to Kernel.open does not call it.  But it seems to  
work...

Ashley


--
blog @ http://aviewfromafar.net/
linked-in @ http://www.linkedin.com/in/ashleymoran
currently @ home



More information about the rspec-users mailing list