lib/httpx/adapters/webmock.rb in httpx-1.1.5 vs lib/httpx/adapters/webmock.rb in httpx-1.2.0
- old
+ new
@@ -39,25 +39,47 @@
return build_error_response(request, webmock_response.exception) if webmock_response.exception
request.options.response_class.new(request,
webmock_response.status[0],
"2.0",
- webmock_response.headers)
+ webmock_response.headers).tap do |res|
+ res.mocked = true
+ end
end
def build_error_response(request, exception)
HTTPX::ErrorResponse.new(request, exception, request.options)
end
end
module InstanceMethods
- def build_connection(*)
+ def init_connection(*)
connection = super
connection.once(:unmock_connection) do
+ unless connection.addresses
+ connection.__send__(:callbacks)[:connect_error].clear
+ pool.__send__(:unregister_connection, connection)
+ end
pool.__send__(:resolve_connection, connection)
- pool.__send__(:unregister_connection, connection) unless connection.addresses
end
connection
+ end
+ end
+
+ module ResponseMethods
+ attr_accessor :mocked
+
+ def initialize(*)
+ super
+ @mocked = false
+ end
+ end
+
+ module ResponseBodyMethods
+ def decode_chunk(chunk)
+ return chunk if @response.mocked
+
+ super
end
end
module ConnectionMethods
def initialize(*)