문제

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?

도움이 되었습니까?

해결책

WebMock has recently added Curb support. :)

http://github.com/bblimke/webmock

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top