Skip to content
Browse files

HTTPClient adapter is switched on/off by WebMock.enable!/disable!

  • Loading branch information...
1 parent ff0ccfe commit a2a1773076c0ad5947b7604599caccc0a917ce34 @bblimke committed Aug 13, 2011
View
6 lib/webmock.rb
@@ -9,11 +9,11 @@
require 'webmock/http_lib_adapters/http_lib_adapter_registry'
require 'webmock/http_lib_adapters/http_lib_adapter'
require 'webmock/http_lib_adapters/net_http'
-require 'webmock/http_lib_adapters/httpclient'
+require 'webmock/http_lib_adapters/httpclient_adapter'
require 'webmock/http_lib_adapters/patron_adapter'
-require 'webmock/http_lib_adapters/curb'
+require 'webmock/http_lib_adapters/curb_adapter'
require 'webmock/http_lib_adapters/em_http_request_adapter'
-require 'webmock/http_lib_adapters/typhoeus_hydra'
+require 'webmock/http_lib_adapters/typhoeus_hydra_adapter'
require 'webmock/errors'
View
0 lib/webmock/http_lib_adapters/curb.rb → ...webmock/http_lib_adapters/curb_adapter.rb
File renamed without changes.
View
23 lib/webmock/http_lib_adapters/httpclient.rb → ...k/http_lib_adapters/httpclient_adapter.rb
@@ -6,7 +6,28 @@
if defined?(::HTTPClient)
- class ::HTTPClient
+ module WebMock
+ module HttpLibAdapters
+ class HTTPClientAdapter < HttpLibAdapter
+ adapter_for :httpclient
+
+ OriginalHttpClient = ::HTTPClient unless const_defined?(:OriginalHttpClient)
+
+ def self.enable!
+ Object.send(:remove_const, :HTTPClient)
+ Object.send(:const_set, :HTTPClient, WebMockHTTPClient)
+ end
+
+ def self.disable!
+ Object.send(:remove_const, :HTTPClient)
+ Object.send(:const_set, :HTTPClient, OriginalHttpClient)
+ end
+ end
+ end
+ end
+
+
+ class WebMockHTTPClient < HTTPClient
def do_get_block_with_webmock(req, proxy, conn, &block)
do_get_with_webmock(req, proxy, conn, false, &block)
View
0 ...bmock/http_lib_adapters/typhoeus_hydra.rb → ...tp_lib_adapters/typhoeus_hydra_adapter.rb
File renamed without changes.

0 comments on commit a2a1773

Please sign in to comment.
Something went wrong with that request. Please try again.