Method: Net::HTTP#request_with_fakeweb

Defined in:
lib/fake_web/ext/net_http.rb

#request_with_fakeweb(request, body = nil, &block) ⇒ Object Also known as: request



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fake_web/ext/net_http.rb', line 38

def request_with_fakeweb(request, body = nil, &block)
  FakeWeb.last_request = request

  uri = FakeWeb::Utility.request_uri_as_string(self, request)
  method = request.method.downcase.to_sym

  if FakeWeb.registered_uri?(method, uri)
    @socket = Net::HTTP.socket_type.new
    FakeWeb::Utility.produce_side_effects_of_net_http_request(request, body)
    FakeWeb.response_for(method, uri, &block)
  elsif FakeWeb.allow_net_connect?(uri)
    connect_without_fakeweb
    request_without_fakeweb(request, body, &block)
  else
    uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
    raise FakeWeb::NetConnectNotAllowedError,
          "Real HTTP connections are disabled. Unregistered request: #{request.method} #{uri}"
  end
end