{"record":{"id":"d2caff0c3e5f1043","repo":"bblimke/webmock","slug":"real-http-connections-are-disabled-unregistered-r-d2caff","errorCode":null,"errorMessage":"Real HTTP connections are disabled. Unregistered request: #{request_signature}","messagePattern":"Real HTTP connections are disabled\\. Unregistered request: #(.+?)","errorType":"exception","errorClass":"WebMock::NetConnectNotAllowedError","httpStatus":null,"severity":"error","filePath":"lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb","lineNumber":182,"sourceCode":"            request.block_connection = false;\n\n            ::WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)\n\n            if webmock_response = ::WebMock::StubRegistry.instance.response_for_request(request_signature)\n              # ::WebMock::HttpLibAdapters::TyphoeusAdapter.stub_typhoeus(request_signature, webmock_response, self)\n              response = ::WebMock::HttpLibAdapters::TyphoeusAdapter.generate_typhoeus_response(request_signature, webmock_response)\n              if request.respond_to?(:on_headers)\n                request.execute_headers_callbacks(response)\n              end\n              if request.respond_to?(:streaming?) && request.streaming?\n                response.options[:response_body] = \"\".dup\n                request.on_body.each { |callback| callback.call(webmock_response.body, response) }\n              end\n              request.finish(response)\n              webmock_response.raise_error_if_any\n              res = false\n            elsif !WebMock.net_connect_allowed?(request_signature.uri)\n              raise WebMock::NetConnectNotAllowedError.new(request_signature)\n            end\n          end\n          res\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":164,"sourceCodeEnd":191,"githubUrl":"https://github.com/bblimke/webmock/blob/b187df8827e1f08a1684a8ddc0a5050dbd449c16/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb#L164-L191","documentation":"WebMock replaces real HTTP with registered stubs while tests run. When the Typhoeus/Hydra adapter intercepts a request whose signature matches no registered stub, and real connections are disabled (the default once WebMock is enabled via disable_net_connect!), it raises WebMock::NetConnectNotAllowedError from lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:182. The message prints the full request signature (method, URI, headers, body) and the list of registered stubs so you can see why nothing matched. This is the tool working as designed: a test must not silently hit the live network.","triggerScenarios":"Running Typhoeus.get('https://api.example.com/v1/x') or a Typhoeus::Hydra parallel run in a spec where no stub_request(:get, 'https://api.example.com/v1/x') was registered. Also near-miss stubs: the stub omits or mismatches query params, the URI differs by trailing slash, default port or subdomain, or headers/body differ, so signature matching fails and the request counts as unregistered. Any side request the test forgot (background job, webhook callback, version-check ping) hits the same raise.","commonSituations":"A new endpoint was added to the client but not stubbed in the spec; spec_helper/rails_helper or another gem calls WebMock.disable_net_connect! globally; the code under test builds URLs dynamically (random ids, timestamps) so the literal stub URI never matches; the stub is registered inside a let/conditional that never runs; hitting localhost without allow_localhost: true; a dependency upgrade makes an extra telemetry request.","solutions":["Read the error output: it prints the exact request signature and a ready-to-copy stub_request snippet - paste that snippet into the spec and chain .to_return(status:, body:, headers:)","If the mismatch is subtle, diff the unregistered signature against the registered stubs listed in the message; fix query params (add them to the stub URI or .with(query: {...})), trailing slashes, or header differences","If this request is meant to be real, open network access selectively: WebMock.disable_net_connect!(allow_localhost: true) or WebMock.disable_net_connect!(allow: ['api.example.com']), or fully with WebMock.allow_net_connect!","If Typhoeus must not be intercepted in this suite, exclude the adapter: WebMock.disable!(except: [:typhoeus])"],"exampleFix":"// before\nit 'lists users' do\n  Typhoeus.get('https://api.example.com/v1/users')  # NetConnectNotAllowedError: unregistered request\nend\n\n// after\nit 'lists users' do\n  stub_request(:get, 'https://api.example.com/v1/users')\n    .to_return(status: 200, body: '[{\"id\":1}]', headers: { 'Content-Type' => 'application/json' })\n  Typhoeus.get('https://api.example.com/v1/users')\nend","handlingStrategy":"validation","validationCode":"# Before the code under test runs, assert a stub really covers the request:\nsig = WebMock::RequestSignature.new(:get, 'https://api.example.com/v1/users')\nraise 'no stub covers this request' unless WebMock.registered_request?(sig)","typeGuard":null,"tryCatchPattern":"begin\n  Typhoeus.get(url)\nrescue WebMock::NetConnectNotAllowedError => e\n  WebMock.print_executed_requests  # executed vs registered diff\n  raise\nend","preventionTips":["Register stubs in before hooks or lets that always run, never inside conditionals","Call WebMock.print_executed_requests in your rescue to see the executed-vs-registered diff","Use WebMock.disable_net_connect!(allow_localhost: true) or allow: [...] in suites that legitimately touch real hosts","Stub the host broadly (stub_request(:any, %r{api\\.example\\.com})) so extra sub-paths still match"],"tags":["webmock","typhoeus","http-stubbing","test-failure","ruby"],"backgroundTag":"http-request-not-stubbed","analyzedSha":"b187df8827e1f08a1684a8ddc0a5050dbd449c16","analyzedAt":"2026-08-23T02:55:22.028Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}