Permalink
Browse files

Redefined const_defined? on the replaced Net::HTTP so that it returns…

… true if constant is defined on the original Net::HTTP.

This is only for Ruby 1.8 since Ruby 1.9 by default looks for a const in ancestors.
  • Loading branch information...
1 parent 8edff05 commit 6d285bdbccba726f63181715f37530a2ef3d47fd @bblimke committed Aug 15, 2011
Showing with 10 additions and 0 deletions.
  1. +6 −0 lib/webmock/http_lib_adapters/net_http.rb
  2. +4 −0 spec/net_http_spec.rb
@@ -74,6 +74,12 @@ def socket_type_with_webmock
end
alias_method :socket_type_without_webmock, :socket_type
alias_method :socket_type, :socket_type_with_webmock
+
+ if ::RUBY_VERSION =~ /1.8/
+ def const_defined?(name)
+ super || self.superclass.const_defined?(name)
+ end
+ end
end
def request_with_webmock(request, body = nil, &block)
View
@@ -11,6 +11,10 @@
let(:port){ WebMockServer.instance.port }
+ it "should still have const Get defined on replaced Net::HTTP" do
+ Object.const_get("Net").const_get("HTTP").const_defined?("Get").should be_true
+ end
+
it "should work with block provided" do
stub_http_request(:get, "www.example.com").to_return(:body => "abc"*100000)
Net::HTTP.start("www.example.com") { |query| query.get("/") }.body.should == "abc"*100000

0 comments on commit 6d285bd

Please sign in to comment.