Skip to content

Commit 90f0bb7

Browse files
authored
Merge pull request #796 from TienDo1011/more-straight-forward-c-perform
[ready] perform should reset webmock_method after making request
2 parents e386be1 + 3852a81 commit 90f0bb7

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/webmock/http_lib_adapters/curb_adapter.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def self.parse_header_string(header_string)
5454

5555
module Curl
5656
class WebMockCurlEasy < Curl::Easy
57-
5857
def curb_or_webmock
5958
request_signature = build_request_signature
6059
WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
@@ -271,6 +270,8 @@ def http_post *data
271270
def perform
272271
@webmock_method ||= :get
273272
curb_or_webmock { super }
273+
ensure
274+
reset_webmock_method
274275
end
275276

276277
def put_data= data
@@ -333,6 +334,10 @@ def on_#{callback} &block
333334
METHOD
334335
end
335336

337+
def reset_webmock_method
338+
@webmock_method = :get
339+
end
340+
336341
def reset
337342
instance_variable_set(:@body_str, nil)
338343
super

spec/acceptance/curb/curb_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,17 @@
411411
it_should_behave_like "Curb"
412412
include CurbSpecHelper::NamedHttp
413413

414+
it "should reset @webmock_method after each call" do
415+
stub_request(:post, "www.example.com").with(body: "01234")
416+
c = Curl::Easy.new
417+
c.url = "http://www.example.com"
418+
c.post_body = "01234"
419+
c.http_post
420+
expect {
421+
c.perform
422+
}.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com))
423+
end
424+
414425
it "should work with blank arguments for post" do
415426
stub_request(:post, "www.example.com").with(body: "01234")
416427
c = Curl::Easy.new

0 commit comments

Comments
 (0)