Skip to content

Commit

Permalink
monkeypatch webmock
Browse files Browse the repository at this point in the history
  • Loading branch information
jlbyrne committed May 21, 2024
1 parent e211b36 commit 00c7aea
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@
config.allow_http_connections_when_no_cassette = false
config.default_cassette_options = {match_requests_on: %i[method uri body], decode_compressed_response: true}
end

module WebMock
# class RequestPattern
# alias_method :_matches?, :matches?

# def matches?(request_signature)
# return if request_signature.uri.host == '127.0.0.1' && request_signature.uri.path == '/__identify__'
# _matches?(request_signature)
# end
# end

def self.net_connect_explicit_allowed?(allowed, uri=nil)
case allowed
when Array
allowed.any? { |allowed_item| net_connect_explicit_allowed?(allowed_item, uri) }
when Regexp
(uri.to_s =~ allowed) != nil ||
(uri.omit(:port).to_s =~ allowed) != nil && uri.port == uri.default_port
when String
allowed == uri.to_s ||
allowed == uri.host ||
allowed == "#{uri.host}:#{uri.port}" ||
allowed == "#{uri.scheme}://#{uri.host}:#{uri.port}" ||
(allowed == uri.omit(:port).to_s && uri.port == uri.default_port)
else
if allowed.respond_to?(:call)
allowed.call(uri)
end
end
end
end

module ActiveSupport
class TestCase
include ServiceClassHelpers
Expand Down

0 comments on commit 00c7aea

Please sign in to comment.