Skip to content

Commit

Permalink
Merge pull request #263 from bastien/bastien/multiple-regex-in-allow
Browse files Browse the repository at this point in the history
multiple regex in allow
  • Loading branch information
bblimke committed Mar 17, 2013
2 parents 1ee340f + 3122c7f commit d85e2cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/webmock/webmock.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ def self.net_connect_allowed?(uri = nil)
end end


Config.instance.allow_net_connect || Config.instance.allow_net_connect ||
( ( Config.instance.allow_localhost && WebMock::Util::URI.is_uri_localhost?(uri) ||
Config.instance.allow_localhost && WebMock::Util::URI.is_uri_localhost?(uri)) || Config.instance.allow && net_connect_explicit_allowed?(Config.instance.allow, uri) )
Config.instance.allow && ( end
(Config.instance.allow.kind_of?(Regexp) && uri.to_s =~ Config.instance.allow) ||
( def self.net_connect_explicit_allowed?(allowed, uri=nil)
Config.instance.allow.respond_to?(:include?) && case allowed
( when Array
Config.instance.allow.include?(uri.host) || allowed.any? { |allowed_item| net_connect_explicit_allowed?(allowed_item, uri) }
Config.instance.allow.include?("#{uri.host}:#{uri.port}") when Regexp
) uri.to_s =~ allowed
) when String
) allowed == uri.host ||
allowed == "#{uri.host}:#{uri.port}"
end
end end


def self.reset! def self.reset!
Expand Down
5 changes: 5 additions & 0 deletions spec/acceptance/net_http/net_http_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ class TestMarshalingInWebMockNetHTTP
response = Net::HTTP.get('www.google.com','/') response = Net::HTTP.get('www.google.com','/')
end end


it "should connect to the server if the URI matches any regex the array", :net_connect => true do
WebMock.disable_net_connect!(:allow => [/google.com/, /yahoo.com/])
response = Net::HTTP.get('www.google.com','/')
end

end end


end end
Expand Down

0 comments on commit d85e2cf

Please sign in to comment.