From 5108a6247f152ae3d28d5e9161155745ece1d235 Mon Sep 17 00:00:00 2001 From: Kevin Elliott Date: Tue, 25 Apr 2023 07:25:07 +0000 Subject: [PATCH] Fix WebMock adapter so that it gets disabled when WebMock gets disabled --- integration_tests/webmock_test.rb | 10 ++++++++++ lib/httpx/adapters/webmock.rb | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/integration_tests/webmock_test.rb b/integration_tests/webmock_test.rb index a61d9b8b..b459d4e8 100644 --- a/integration_tests/webmock_test.rb +++ b/integration_tests/webmock_test.rb @@ -204,6 +204,16 @@ class WebmockTest < Minitest::Test WebMock.disable_net_connect! end + def test_webmock_disable_after_enable + WebMock.disable! + + # WebMock is disabled so this will make a real http request + http_request(:get, "http://#{httpbin}") + + # WebMock is disabled so it should not have registered the request + assert_not_requested(:get, "http://#{httpbin}") + end + private def assert_raise_with_message(e, message, &block) diff --git a/lib/httpx/adapters/webmock.rb b/lib/httpx/adapters/webmock.rb index f73677eb..07bea9d5 100644 --- a/lib/httpx/adapters/webmock.rb +++ b/lib/httpx/adapters/webmock.rb @@ -122,7 +122,7 @@ module WebMock class << self def enable! - @original_session = HTTPX::Session + @original_session ||= HTTPX::Session webmock_session = HTTPX.plugin(Plugin)