Skip to content

Commit eaf3714

Browse files
committed
Add curb_adapter http_patch
1 parent 56cb661 commit eaf3714

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

lib/webmock/http_lib_adapters/curb_adapter.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ def http(method)
255255
end
256256
end
257257

258+
def http_patch data = nil
259+
@webmock_method = :patch
260+
@post_body = data if data
261+
super
262+
end
263+
alias patch http_patch
264+
258265
def http_put data = nil
259266
@webmock_method = :put
260267
@put_data = data if data
@@ -287,6 +294,11 @@ def post_body= data
287294
super
288295
end
289296

297+
def patch_body= data
298+
self.post_body = data
299+
@webmock_method = :patch
300+
end
301+
290302
def delete= value
291303
@webmock_method = :delete if value
292304
super

spec/acceptance/curb/curb_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
status).to eq("200")
1717
end
1818
end
19+
20+
describe "when doing PATCHes" do
21+
it "should stub them" do
22+
stub_request(:patch, "www.example.com").with(body: "01234")
23+
expect(http_request(:patch, "http://www.example.com", body: "01234").
24+
status).to eq("200")
25+
end
26+
end
1927
end
2028

2129
describe "Curb features" do
@@ -457,6 +465,15 @@
457465
expect(c.response_code).to eq(200)
458466
end
459467

468+
it "should work with blank arguments for patch" do
469+
stub_request(:patch, "www.example.com").with(body: "01234")
470+
c = Curl::Easy.new
471+
c.url = "http://www.example.com"
472+
c.patch_body = "01234"
473+
c.http_patch
474+
expect(c.response_code).to eq(200)
475+
end
476+
460477
it "should work with multiple arguments for post" do
461478
data = { name: "john", address: "111 example ave" }
462479

spec/acceptance/curb/curb_spec_helper.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def curb_http_request(uri, method, body, options)
6868
case method
6969
when :post
7070
curl.post_body = body
71+
when :patch
72+
curl.patch_body = body
7173
when :put
7274
curl.put_data = body
7375
end
@@ -82,7 +84,7 @@ def curb_http_request(uri, method, body, options)
8284
curl = setup_request(uri, nil, options)
8385

8486
case method
85-
when :put, :post
87+
when :put, :post, :patch
8688
curl.send( "http_#{method}", body )
8789
else
8890
curl.send( "http_#{method}" )
@@ -98,6 +100,8 @@ def curb_http_request(uri, method, body, options)
98100
case method
99101
when :post
100102
curl.post_body = body
103+
when :patch
104+
curl.patch_body = body
101105
when :put
102106
curl.put_data = body
103107
when :head
@@ -114,7 +118,7 @@ def curb_http_request(uri, method, body, options)
114118
module ClassNamedHttp
115119
def curb_http_request(uri, method, body, options)
116120
args = ["http_#{method}", uri]
117-
args << body if method == :post || method == :put
121+
args << body if %i[patch put post].include?(method)
118122

119123
c = Curl::Easy.send(*args) do |curl|
120124
setup_request(uri, curl, options)
@@ -127,14 +131,16 @@ def curb_http_request(uri, method, body, options)
127131
module ClassPerform
128132
def curb_http_request(uri, method, body, options)
129133
args = ["http_#{method}", uri]
130-
args << body if method == :post || method == :put
134+
args << body if %i[patch put post].include?(method)
131135

132136
c = Curl::Easy.send(*args) do |curl|
133137
setup_request(uri, curl, options)
134138

135139
case method
136140
when :post
137141
curl.post_body = body
142+
when :patch
143+
curl.patch_body = body
138144
when :put
139145
curl.put_data = body
140146
when :head

0 commit comments

Comments
 (0)