FakeWebでHTTPリクエストをモックする

chrisk/fakeweb · GitHub

Gemfile

require 'fakeweb'

使い方はこんな感じ

FakeWeb.register_uri(:get, "http://example.com/test1", :body => "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