Skip to content
Browse files

Fixed problem with Net::HTTP::DigestAuth. All constants are set back …

…on original Net::HTTP, after WebMock is disabled, if any constants were added to Net::HTTP after WebMock was enabled.
  • Loading branch information...
1 parent 806818f commit 1acfa58e578b3e895e99bec13695957a4838991b @bblimke committed Aug 26, 2012
Showing with 21 additions and 0 deletions.
  1. +8 −0 lib/webmock/http_lib_adapters/net_http.rb
  2. +13 −0 spec/acceptance/net_http/net_http_spec.rb
View
8 lib/webmock/http_lib_adapters/net_http.rb
@@ -28,6 +28,14 @@ def self.disable!
Net.send(:const_set, :HTTP, OriginalNetHTTP)
Net.send(:const_set, :HTTPSession, OriginalNetHTTP)
Net.send(:const_set, :BufferedIO, OriginalNetBufferedIO)
+
+ #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 - OriginalNetHTTP.constants).each do |constant|
+ OriginalNetHTTP.send(:const_set, constant, @webMockNetHTTP.const_get(constant))
+ end
end
@webMockNetHTTP = Class.new(Net::HTTP) do
View
13 spec/acceptance/net_http/net_http_spec.rb
@@ -86,6 +86,19 @@ class TestMarshalingInWebMockNetHTTP
Object.const_get("Net").const_get("HTTP").constants(false).map(&:to_s).should include("Get")
end
end
+
+ describe "after WebMock is disabled" do
+ after(:each) do
+ WebMock.enable!
+ end
+ it "Net::HTTP should have the same constants" do
+ orig_consts_number = Net::HTTP.constants.size
+ Net::HTTP.send(:const_set, "TEST_CONST", 10)
+ Net::HTTP.constants.size.should == orig_consts_number + 1
+ WebMock.disable!
+ Net::HTTP.constants.size.should == orig_consts_number + 1
+ end
+ end
end
it "should work with block provided" do

0 comments on commit 1acfa58

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