views:

45

answers:

2

Is there a way to mock out Curb's Easy.perform method for unit testing? I use this to hit Facebook's graph API, and none of the http mock libs seem to support Curb.

What's the best approach here?

A: 

I really think fakeWeb is a great way to fake out network calls; Whatever HTTP library you use, you'll just specify what response text and code you want to receive.

Described as:

FakeWeb is a helper for faking web requests in Ruby. It works at a global level, without modifying code or writing extensive stubs

Example from the github repository:

FakeWeb.register_uri(:get, "http://example.com/test1", :string => "Hello World!")

Net::HTTP.get(URI.parse("http://example.com/test1"))
=> "Hello World!"

Net::HTTP.get(URI.parse("http://example.com/test2"))
=> FakeWeb is bypassed and the response from a real request is returned
Jesse Wolgamott
Yes fakeweb is great, but the default curb install is going to Wrap Curl, and not use Net:HTTP, so Fakeweb will not be able to intercept the calls. I was running into the same issue when testing soap services and the like and wound up using SOAP-ui to build the mocks
Doon
@Doon ... you're right! Learn something new every day. And Curb support is an issue on http://github.com/chrisk/fakeweb/issues#issue/10
Jesse Wolgamott
I was toying with the idea of just not including curb support (via Gemfile as this was a rails 3 test app), trying to force it back to use Net::HTTP. I think it will work, but I already had the mock services in place, and soap-ui gave me better options to provide different data in the calls. so I give up and went back to coding. The only down side is that if I forget to start the mocks I get lots of errors.. But I can live with it.
Doon
A: 

WebMock has recently added Curb support. :)

http://github.com/bblimke/webmock

Josiah Kiehl