Skip to content

Commit

Permalink
Add JSON API support
Browse files Browse the repository at this point in the history
  • Loading branch information
ouranos committed Dec 28, 2017
1 parent 08b41bc commit 2a1185b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/webmock/request_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,17 @@ class BodyPattern
include RSpecMatcherDetector

BODY_FORMATS = {
'text/xml' => :xml,
'application/xml' => :xml,
'application/json' => :json,
'text/json' => :json,
'application/javascript' => :json,
'text/javascript' => :json,
'text/html' => :html,
'application/x-yaml' => :yaml,
'text/yaml' => :yaml,
'text/plain' => :plain
'text/xml' => :xml,
'application/xml' => :xml,
'application/json' => :json,
'application/vnd.api+json' => :json,
'text/json' => :json,
'application/javascript' => :json,
'text/javascript' => :json,
'text/html' => :html,
'application/x-yaml' => :yaml,
'text/yaml' => :yaml,
'text/plain' => :plain
}

attr_reader :pattern
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/request_pattern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ def match(request_signature)
body: "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}"))
end

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

it "should not match when body is not json" do
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
Expand Down

0 comments on commit 2a1185b

Please sign in to comment.