Tutorial :Mock out Curl::Easy.perform? (in Curb)



Question:

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?


Solution:1

WebMock has recently added Curb support. :)

http://github.com/bblimke/webmock


Solution:2

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  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »