pact-support 1.6.6 → 1.7.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 +9 -0
- data/lib/pact/configuration.rb +4 -0
- data/lib/pact/consumer_contract/request.rb +1 -5
- data/lib/pact/matchers/multipart_form_diff_formatter.rb +41 -0
- data/lib/pact/shared/multipart_form_differ.rb +14 -0
- data/lib/pact/support/version.rb +1 -1
- data/spec/fixtures/multipart-form-diff.txt +9 -0
- data/spec/lib/pact/matchers/multipart_form_diff_formatter_spec.rb +36 -0
- data/spec/lib/pact/shared/multipart_form_differ_spec.rb +39 -0
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bbba1bbc7c4a2bf0c9bf83c335bca49f3911b33
|
|
4
|
+
data.tar.gz: 074b3a5fbf4ea09514e9a58d6af2d42d22739942
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d15ba35784d2b6a93feeae4f77fd43f32ae2b07d3ece6b1b1a0367d9d05702a6a6dca9696e65287ba782c2ccfc495fc7fb3c8e8a34c57f525ddaf0702acdf6b2
|
|
7
|
+
data.tar.gz: 58ebf78d2b351442c2d3ac0ce8a2874949939acb51ca94b5aa7f0b261b1674da0ddd73db983e643267e9dd3b8c0117a80277090ac36690ff71ece9fbb694c118
|
data/CHANGELOG.md
CHANGED
data/lib/pact/configuration.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
require 'pact/matchers/embedded_diff_formatter'
|
|
2
2
|
require 'pact/matchers/unix_diff_formatter'
|
|
3
3
|
require 'pact/matchers/list_diff_formatter'
|
|
4
|
+
require 'pact/matchers/multipart_form_diff_formatter'
|
|
4
5
|
require 'pact/shared/json_differ'
|
|
5
6
|
require 'pact/shared/text_differ'
|
|
6
7
|
require 'pact/shared/form_differ'
|
|
8
|
+
require 'pact/shared/multipart_form_differ'
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
module Pact
|
|
@@ -24,6 +26,7 @@ module Pact
|
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
DIFF_FORMATTER_REGISTRATIONS = [
|
|
29
|
+
[/multipart\/form-data/, Pact::Matchers::MultipartFormDiffFormatter],
|
|
27
30
|
[/.*/, Pact::Matchers::UnixDiffFormatter],
|
|
28
31
|
[NilMatcher, Pact::Matchers::UnixDiffFormatter]
|
|
29
32
|
]
|
|
@@ -31,6 +34,7 @@ module Pact
|
|
|
31
34
|
DIFFERS = [
|
|
32
35
|
[/json/, Pact::JsonDiffer],
|
|
33
36
|
[/application\/x\-www\-form\-urlencoded/, Pact::FormDiffer],
|
|
37
|
+
[/multipart\/form-data/, Pact::MultipartFormDiffer],
|
|
34
38
|
[NilMatcher, Pact::TextDiffer],
|
|
35
39
|
[/.*/, Pact::TextDiffer]
|
|
36
40
|
]
|
|
@@ -2,9 +2,7 @@ require 'pact/shared/request'
|
|
|
2
2
|
require 'pact/shared/null_expectation'
|
|
3
3
|
|
|
4
4
|
module Pact
|
|
5
|
-
|
|
6
5
|
module Request
|
|
7
|
-
|
|
8
6
|
class Expected < Pact::Request::Base
|
|
9
7
|
|
|
10
8
|
DEFAULT_OPTIONS = {:allow_unexpected_keys => false}.freeze
|
|
@@ -80,8 +78,6 @@ module Pact
|
|
|
80
78
|
def body_differ
|
|
81
79
|
Pact.configuration.body_differ_for_content_type content_type
|
|
82
80
|
end
|
|
83
|
-
|
|
84
81
|
end
|
|
85
|
-
|
|
86
82
|
end
|
|
87
|
-
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'pact/matchers/unix_diff_formatter'
|
|
2
|
+
require 'pact/matchers/differ'
|
|
3
|
+
|
|
4
|
+
module Pact
|
|
5
|
+
module Matchers
|
|
6
|
+
class MultipartFormDiffFormatter
|
|
7
|
+
|
|
8
|
+
def initialize diff, options = {}
|
|
9
|
+
@options = options
|
|
10
|
+
@body_diff = diff[:body]
|
|
11
|
+
@non_body_diff = diff.reject{ |k, v| k == :body }
|
|
12
|
+
@colour = options.fetch(:colour, false)
|
|
13
|
+
@differ = Pact::Matchers::Differ.new(@colour)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.call diff, options = {}
|
|
17
|
+
new(diff, options).call
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def call
|
|
21
|
+
Pact::Matchers::UnixDiffFormatter::MESSAGES_TITLE + "\n" + non_body_diff_string + "\n" + body_diff_string
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def non_body_diff_string
|
|
25
|
+
if @non_body_diff.any?
|
|
26
|
+
Pact::Matchers::ExtractDiffMessages.call(@non_body_diff).collect{ | message| "* #{message}" }.join("\n")
|
|
27
|
+
else
|
|
28
|
+
""
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def body_diff_string
|
|
33
|
+
if @body_diff
|
|
34
|
+
@differ.diff_as_string(@body_diff.expected, @body_diff.actual)
|
|
35
|
+
else
|
|
36
|
+
""
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'pact/shared/text_differ'
|
|
3
|
+
|
|
4
|
+
module Pact
|
|
5
|
+
class MultipartFormDiffer
|
|
6
|
+
def self.call expected, actual, options = {}
|
|
7
|
+
require 'pact/matchers' # avoid recursive loop between this file and pact/matchers
|
|
8
|
+
expected_boundary = expected.split.first
|
|
9
|
+
actual_boundary = actual.split.first
|
|
10
|
+
actual_with_hardcoded_boundary = actual.gsub(actual_boundary, expected_boundary)
|
|
11
|
+
TextDiffer.call(expected, actual_with_hardcoded_boundary, options)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/pact/support/version.rb
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'pact/matchers/multipart_form_diff_formatter'
|
|
2
|
+
|
|
3
|
+
module Pact
|
|
4
|
+
module Matchers
|
|
5
|
+
describe MultipartFormDiffFormatter do
|
|
6
|
+
describe ".call" do
|
|
7
|
+
subject { MultipartFormDiffFormatter.call(diff, options)}
|
|
8
|
+
|
|
9
|
+
let(:diff) do
|
|
10
|
+
{
|
|
11
|
+
headers: header_diff,
|
|
12
|
+
body: body_diff
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:header_diff) do
|
|
17
|
+
{
|
|
18
|
+
"Content-Type" => Difference.new("foo", "bar", "Wrong header")
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
let(:body_diff) do
|
|
23
|
+
Difference.new("foo", "bar", "A message")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:options) { {} }
|
|
27
|
+
|
|
28
|
+
let(:expected_output) { File.read("spec/fixtures/multipart-form-diff.txt")}
|
|
29
|
+
|
|
30
|
+
it "formats the diff" do
|
|
31
|
+
expect(subject).to eq expected_output
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'pact/shared/multipart_form_differ'
|
|
2
|
+
|
|
3
|
+
module Pact
|
|
4
|
+
describe MultipartFormDiffer do
|
|
5
|
+
|
|
6
|
+
describe ".call" do
|
|
7
|
+
|
|
8
|
+
let(:expected_body) do
|
|
9
|
+
"-------------RubyMultipartPost-1e4912957c7bb64de3c444568326663b\r\nContent-Disposition: form-data; name=\"file\"; filename=\"text.txt\"\r\nContent-Length: 14\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nThis is a file\r\n-------------RubyMultipartPost-1e4912957c7bb64de3c444568326663b--\r\n\r\n"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:actual_body) do
|
|
13
|
+
"-------------RubyMultipartPost-1e4912957c7bb64de3c4445683266XXX\r\nContent-Disposition: form-data; name=\"file\"; filename=\"text.txt\"\r\nContent-Length: 14\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nThis is a file\r\n-------------RubyMultipartPost-1e4912957c7bb64de3c4445683266XXX--\r\n\r\n"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:options) do
|
|
17
|
+
{}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
subject { MultipartFormDiffer.call(expected_body, actual_body, options) }
|
|
21
|
+
|
|
22
|
+
context "when the bodies are the same apart from the boundary" do
|
|
23
|
+
it "returns an empty diff" do
|
|
24
|
+
expect(subject).to eq({})
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "when the bodies are not the same" do
|
|
29
|
+
let(:actual_body) do
|
|
30
|
+
"-------------RubyMultipartPost-1e4912957c7bb64de3c4445683266XXX\r\nContent-Disposition: form-data; name=\"file\"; filename=\"bar.txt\"\r\nContent-Length: 14\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nThis is a file\r\n-------------RubyMultipartPost-1e4912957c7bb64de3c4445683266XXX--\r\n\r\n"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "returns a text diff" do
|
|
34
|
+
expect(subject).to_not eq({})
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pact-support
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Fraser
|
|
@@ -12,7 +12,7 @@ authors:
|
|
|
12
12
|
autorequire:
|
|
13
13
|
bindir: bin
|
|
14
14
|
cert_chain: []
|
|
15
|
-
date: 2018-
|
|
15
|
+
date: 2018-08-06 00:00:00.000000000 Z
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
18
18
|
name: randexp
|
|
@@ -297,6 +297,7 @@ files:
|
|
|
297
297
|
- lib/pact/matchers/index_not_found.rb
|
|
298
298
|
- lib/pact/matchers/list_diff_formatter.rb
|
|
299
299
|
- lib/pact/matchers/matchers.rb
|
|
300
|
+
- lib/pact/matchers/multipart_form_diff_formatter.rb
|
|
300
301
|
- lib/pact/matchers/no_diff_at_index.rb
|
|
301
302
|
- lib/pact/matchers/regexp_difference.rb
|
|
302
303
|
- lib/pact/matchers/type_difference.rb
|
|
@@ -317,6 +318,7 @@ files:
|
|
|
317
318
|
- lib/pact/shared/jruby_support.rb
|
|
318
319
|
- lib/pact/shared/json_differ.rb
|
|
319
320
|
- lib/pact/shared/key_not_found.rb
|
|
321
|
+
- lib/pact/shared/multipart_form_differ.rb
|
|
320
322
|
- lib/pact/shared/null_expectation.rb
|
|
321
323
|
- lib/pact/shared/request.rb
|
|
322
324
|
- lib/pact/shared/text_differ.rb
|
|
@@ -331,6 +333,7 @@ files:
|
|
|
331
333
|
- script/release.sh
|
|
332
334
|
- script/update-pact-specification-v2
|
|
333
335
|
- spec/fixtures/interaction-with-matching-rules.json
|
|
336
|
+
- spec/fixtures/multipart-form-diff.txt
|
|
334
337
|
- spec/fixtures/not-a-pact.json
|
|
335
338
|
- spec/fixtures/pact-http-v2.json
|
|
336
339
|
- spec/fixtures/pact-http-v3.json
|
|
@@ -362,6 +365,7 @@ files:
|
|
|
362
365
|
- spec/lib/pact/matchers/matchers_messages_mismatched_value_spec.rb
|
|
363
366
|
- spec/lib/pact/matchers/matchers_messages_regexp_spec.rb
|
|
364
367
|
- spec/lib/pact/matchers/matchers_spec.rb
|
|
368
|
+
- spec/lib/pact/matchers/multipart_form_diff_formatter_spec.rb
|
|
365
369
|
- spec/lib/pact/matchers/no_diff_at_index_spec.rb
|
|
366
370
|
- spec/lib/pact/matchers/regexp_difference_spec.rb
|
|
367
371
|
- spec/lib/pact/matchers/type_difference_spec.rb
|
|
@@ -378,6 +382,7 @@ files:
|
|
|
378
382
|
- spec/lib/pact/shared/form_differ_spec.rb
|
|
379
383
|
- spec/lib/pact/shared/json_differ_spec.rb
|
|
380
384
|
- spec/lib/pact/shared/key_not_found_spec.rb
|
|
385
|
+
- spec/lib/pact/shared/multipart_form_differ_spec.rb
|
|
381
386
|
- spec/lib/pact/shared/request_spec.rb
|
|
382
387
|
- spec/lib/pact/shared/text_differ_spec.rb
|
|
383
388
|
- spec/lib/pact/something_like_spec.rb
|
|
@@ -436,6 +441,7 @@ specification_version: 4
|
|
|
436
441
|
summary: Shared code for Pact gems
|
|
437
442
|
test_files:
|
|
438
443
|
- spec/fixtures/interaction-with-matching-rules.json
|
|
444
|
+
- spec/fixtures/multipart-form-diff.txt
|
|
439
445
|
- spec/fixtures/not-a-pact.json
|
|
440
446
|
- spec/fixtures/pact-http-v2.json
|
|
441
447
|
- spec/fixtures/pact-http-v3.json
|
|
@@ -467,6 +473,7 @@ test_files:
|
|
|
467
473
|
- spec/lib/pact/matchers/matchers_messages_mismatched_value_spec.rb
|
|
468
474
|
- spec/lib/pact/matchers/matchers_messages_regexp_spec.rb
|
|
469
475
|
- spec/lib/pact/matchers/matchers_spec.rb
|
|
476
|
+
- spec/lib/pact/matchers/multipart_form_diff_formatter_spec.rb
|
|
470
477
|
- spec/lib/pact/matchers/no_diff_at_index_spec.rb
|
|
471
478
|
- spec/lib/pact/matchers/regexp_difference_spec.rb
|
|
472
479
|
- spec/lib/pact/matchers/type_difference_spec.rb
|
|
@@ -483,6 +490,7 @@ test_files:
|
|
|
483
490
|
- spec/lib/pact/shared/form_differ_spec.rb
|
|
484
491
|
- spec/lib/pact/shared/json_differ_spec.rb
|
|
485
492
|
- spec/lib/pact/shared/key_not_found_spec.rb
|
|
493
|
+
- spec/lib/pact/shared/multipart_form_differ_spec.rb
|
|
486
494
|
- spec/lib/pact/shared/request_spec.rb
|
|
487
495
|
- spec/lib/pact/shared/text_differ_spec.rb
|
|
488
496
|
- spec/lib/pact/something_like_spec.rb
|