Skip to content

Commit 2a1185b

Browse files
committed
Add JSON API support
1 parent 08b41bc commit 2a1185b

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

lib/webmock/request_pattern.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,17 @@ class BodyPattern
214214
include RSpecMatcherDetector
215215

216216
BODY_FORMATS = {
217-
'text/xml' => :xml,
218-
'application/xml' => :xml,
219-
'application/json' => :json,
220-
'text/json' => :json,
221-
'application/javascript' => :json,
222-
'text/javascript' => :json,
223-
'text/html' => :html,
224-
'application/x-yaml' => :yaml,
225-
'text/yaml' => :yaml,
226-
'text/plain' => :plain
217+
'text/xml' => :xml,
218+
'application/xml' => :xml,
219+
'application/json' => :json,
220+
'application/vnd.api+json' => :json,
221+
'text/json' => :json,
222+
'application/javascript' => :json,
223+
'text/javascript' => :json,
224+
'text/html' => :html,
225+
'application/x-yaml' => :yaml,
226+
'text/yaml' => :yaml,
227+
'text/plain' => :plain
227228
}
228229

229230
attr_reader :pattern

spec/unit/request_pattern_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,12 @@ def match(request_signature)
424424
body: "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}"))
425425
end
426426

427+
it "should match when content type is set to json api" do
428+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
429+
to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: 'application/vnd.api+json'},
430+
body: "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}"))
431+
end
432+
427433
it "should not match when body is not json" do
428434
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
429435
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",

0 commit comments

Comments
 (0)