On 10/19/07, Paul Dlug <[EMAIL PROTECTED]> wrote:
> Is it possible to stub a Kernel method? I'm specifically interested in
> the 'open' method to test some code using open-uri. I've tried:
>
> Kernel.should_receive(:open).with('filename').and_return('data')
>
> However, this doesn't seem to work. Any suggestions would be appreciated.
>
>
> --Paul
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
Kernel gets mixed in to an object, so you need to stub it on the object itself.
describe Newsreader do
it "should open the uri" do
@reader = Newsreader.new
@reader.should_receive(:open_uri).with "http://example.com/feed.xml"
@reader.grab_feed "http://example.com/feed.xml"
end
end
class Newsreader
def grab_feed(uri)
response = open_uri uri
end
end
Pat
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users