Skip to content

Commit

Permalink
Redefined const_defined? on the replaced Net::HTTP so that it returns…
Browse files Browse the repository at this point in the history
… 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
bblimke committed Aug 15, 2011
1 parent 8edff05 commit 6d285bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/webmock/http_lib_adapters/net_http.rb
Expand Up @@ -74,6 +74,12 @@ def socket_type_with_webmock
end end
alias_method :socket_type_without_webmock, :socket_type alias_method :socket_type_without_webmock, :socket_type
alias_method :socket_type, :socket_type_with_webmock 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 end


def request_with_webmock(request, body = nil, &block) def request_with_webmock(request, body = nil, &block)
Expand Down
4 changes: 4 additions & 0 deletions spec/net_http_spec.rb
Expand Up @@ -11,6 +11,10 @@


let(:port){ WebMockServer.instance.port } 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 it "should work with block provided" do
stub_http_request(:get, "www.example.com").to_return(:body => "abc"*100000) 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 Net::HTTP.start("www.example.com") { |query| query.get("/") }.body.should == "abc"*100000
Expand Down

0 comments on commit 6d285bd

Please sign in to comment.