Class: WebMock::HttpLibAdapters::NetHttpAdapter

Inherits:
WebMock::HttpLibAdapter show all
Defined in:
lib/webmock/http_lib_adapters/net_http.rb

Constant Summary collapse

OriginalNetHTTP =
Net::HTTP

Class Method Summary collapse

Methods inherited from WebMock::HttpLibAdapter

adapter_for

Class Method Details

.disable!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/webmock/http_lib_adapters/net_http.rb', line 21

def self.disable!
  Net.send(:remove_const, :HTTP)
  Net.send(:remove_const, :HTTPSession)
  Net.send(:const_set, :HTTP, OriginalNetHTTP)
  Net.send(:const_set, :HTTPSession, OriginalNetHTTP)

  #copy all constants from @webMockNetHTTP to original Net::HTTP
  #in case any constants were added to @webMockNetHTTP instead of Net::HTTP
  #after WebMock was enabled.
  #i.e Net::HTTP::DigestAuth
  @webMockNetHTTP.constants.each do |constant|
    if !OriginalNetHTTP.constants.map(&:to_s).include?(constant.to_s)
      OriginalNetHTTP.send(:const_set, constant, @webMockNetHTTP.const_get(constant))
    end
  end
end

.enable!Object



14
15
16
17
18
19
# File 'lib/webmock/http_lib_adapters/net_http.rb', line 14

def self.enable!
  Net.send(:remove_const, :HTTP)
  Net.send(:remove_const, :HTTPSession)
  Net.send(:const_set, :HTTP, @webMockNetHTTP)
  Net.send(:const_set, :HTTPSession, @webMockNetHTTP)
end