webmock 3.11.3 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -0
- data/lib/webmock/request_pattern.rb +7 -1
- data/lib/webmock/version.rb +1 -1
- data/spec/unit/request_pattern_spec.rb +70 -46
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a63f193f9a6fb608fd8e50b8484cd06bf2ee29765cbe0347b74a6a8e82677be
|
4
|
+
data.tar.gz: bf7b5341dc79029a57c793feb7a7fee2a411a5187f05b1240a3e890842b6300d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbde90987073665a627807880917906602ad10f661f2df95ae038e0e465839bcf98ef76bbc889d0368aa037518ffc0a85239e8cb66a6538600702b0ab72e9cfd
|
7
|
+
data.tar.gz: b47709a8f994adee29b5d6808580af3980dd45b2dd5a539b678897da4779ee306da8d1137bdca324ad8d314e2d0e8f14cb04ce8ea27de4932002c6b2763f3ec1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1156,6 +1156,7 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1156
1156
|
* Oleksiy Kovyrin
|
1157
1157
|
* Matt Larraz
|
1158
1158
|
* Tony Schneider
|
1159
|
+
* Niklas Hösl
|
1159
1160
|
|
1160
1161
|
For a full list of contributors you can visit the
|
1161
1162
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
@@ -295,8 +295,9 @@ module WebMock
|
|
295
295
|
end
|
296
296
|
|
297
297
|
private
|
298
|
+
|
298
299
|
def body_as_hash(body, content_type)
|
299
|
-
case
|
300
|
+
case body_format(content_type)
|
300
301
|
when :json then
|
301
302
|
WebMock::Util::JSON.parse(body)
|
302
303
|
when :xml then
|
@@ -306,6 +307,11 @@ module WebMock
|
|
306
307
|
end
|
307
308
|
end
|
308
309
|
|
310
|
+
def body_format(content_type)
|
311
|
+
normalized_content_type = content_type.sub(/\A(application\/)[a-zA-Z0-9.-]+\+(json|xml)\Z/,'\1\2')
|
312
|
+
BODY_FORMATS[normalized_content_type]
|
313
|
+
end
|
314
|
+
|
309
315
|
def assert_non_multipart_body(content_type)
|
310
316
|
if content_type =~ %r{^multipart/form-data}
|
311
317
|
raise ArgumentError.new("WebMock does not support matching body for multipart/form-data requests yet :(")
|
data/lib/webmock/version.rb
CHANGED
@@ -534,69 +534,93 @@ describe WebMock::RequestPattern do
|
|
534
534
|
end
|
535
535
|
|
536
536
|
describe "for request with json body and content type is set to json" do
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
537
|
+
shared_examples "a json body" do
|
538
|
+
it "should match when hash matches body" do
|
539
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
|
540
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: content_type},
|
541
|
+
body: "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}"))
|
542
|
+
end
|
542
543
|
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
544
|
+
it "should match if hash matches body in different form" do
|
545
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
|
546
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: content_type},
|
547
|
+
body: "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}"))
|
548
|
+
end
|
548
549
|
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
550
|
+
it "should not match when body is not json" do
|
551
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
|
552
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
553
|
+
headers: {content_type: content_type}, body: "foo bar"))
|
554
|
+
end
|
555
|
+
|
556
|
+
it "should not match if request body is different" do
|
557
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: {a: 1, b: 2})).
|
558
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
559
|
+
headers: {content_type: content_type}, body: "{\"a\":1,\"c\":null}"))
|
560
|
+
end
|
554
561
|
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
562
|
+
it "should not match if request body is has less params than pattern" do
|
563
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: {a: 1, b: 2})).
|
564
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
565
|
+
headers: {content_type: content_type}, body: "{\"a\":1}"))
|
566
|
+
end
|
567
|
+
|
568
|
+
it "should not match if request body is has more params than pattern" do
|
569
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: {a: 1})).
|
570
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
571
|
+
headers: {content_type: content_type}, body: "{\"a\":1,\"c\":1}"))
|
572
|
+
end
|
559
573
|
end
|
560
574
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
headers: {content_type: 'application/json'}, body: "{\"a\":1}"))
|
575
|
+
context "standard application/json" do
|
576
|
+
let(:content_type) { 'application/json' }
|
577
|
+
it_behaves_like "a json body"
|
565
578
|
end
|
566
579
|
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
headers: {content_type: 'application/json'}, body: "{\"a\":1,\"c\":1}"))
|
580
|
+
context "custom json content type" do
|
581
|
+
let(:content_type) { 'application/vnd.api+json' }
|
582
|
+
it_behaves_like "a json body"
|
571
583
|
end
|
572
584
|
end
|
573
585
|
|
574
586
|
describe "for request with xml body and content type is set to xml" do
|
575
587
|
let(:body_hash) { {"opt" => {:a => '1', :b => 'five', 'c' => {'d' => ['e', 'f']}}} }
|
576
588
|
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
589
|
+
shared_examples "a xml body" do
|
590
|
+
it "should match when hash matches body" do
|
591
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
|
592
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: content_type},
|
593
|
+
body: "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))
|
594
|
+
end
|
582
595
|
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
596
|
+
it "should match if hash matches body in different form" do
|
597
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
|
598
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: content_type},
|
599
|
+
body: "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))
|
600
|
+
end
|
588
601
|
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
602
|
+
it "should not match when body is not xml" do
|
603
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
|
604
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
605
|
+
headers: {content_type: content_type}, body: "foo bar"))
|
606
|
+
end
|
594
607
|
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
608
|
+
it "matches when the content type include a charset" do
|
609
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
|
610
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: "#{content_type};charset=UTF-8"},
|
611
|
+
body: "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))
|
612
|
+
|
613
|
+
end
|
614
|
+
end
|
615
|
+
|
616
|
+
context "standard application/json" do
|
617
|
+
let(:content_type) { 'application/xml' }
|
618
|
+
it_behaves_like "a xml body"
|
619
|
+
end
|
599
620
|
|
621
|
+
context "custom json content type" do
|
622
|
+
let(:content_type) { 'application/atom+xml' }
|
623
|
+
it_behaves_like "a xml body"
|
600
624
|
end
|
601
625
|
end
|
602
626
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Blimke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -422,9 +422,9 @@ licenses:
|
|
422
422
|
- MIT
|
423
423
|
metadata:
|
424
424
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
425
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/v3.
|
426
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.
|
427
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.
|
425
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.12.0/CHANGELOG.md
|
426
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.12.0
|
427
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.12.0
|
428
428
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
429
429
|
post_install_message:
|
430
430
|
rdoc_options: []
|