pact-support 1.11.0 → 1.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 +16 -0
- data/lib/pact/consumer_contract/consumer_contract.rb +11 -0
- data/lib/pact/consumer_contract/interaction.rb +4 -1
- data/lib/pact/consumer_contract/interaction_v2_parser.rb +9 -1
- data/lib/pact/consumer_contract/interaction_v3_parser.rb +10 -1
- data/lib/pact/support/version.rb +1 -1
- metadata +4 -227
- data/.github/ISSUE_TEMPLATE.md +0 -33
- data/.gitignore +0 -32
- data/.rspec +0 -3
- data/.travis.yml +0 -29
- data/Appraisals +0 -7
- data/Gemfile +0 -4
- data/RELEASING.md +0 -5
- data/Rakefile +0 -4
- data/gemfiles/default.gemfile +0 -5
- data/gemfiles/ruby_under_22.gemfile +0 -8
- data/pact-support.gemspec +0 -39
- data/script/release.sh +0 -9
- data/script/update-pact-specification-v2 +0 -9
- data/spec/fixtures/interaction-with-matching-rules.json +0 -27
- data/spec/fixtures/multipart-form-diff.txt +0 -9
- data/spec/fixtures/not-a-pact.json +0 -3
- data/spec/fixtures/pact-http-v2.json +0 -36
- data/spec/fixtures/pact-http-v3.json +0 -36
- data/spec/integration/matching_rules_extract_and_merge_spec.rb +0 -127
- data/spec/lib/pact/array_like_spec.rb +0 -37
- data/spec/lib/pact/configuration_spec.rb +0 -61
- data/spec/lib/pact/consumer/request_spec.rb +0 -25
- data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -142
- data/spec/lib/pact/consumer_contract/file_name_spec.rb +0 -24
- data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
- data/spec/lib/pact/consumer_contract/http_consumer_contract_parser_spec.rb +0 -25
- data/spec/lib/pact/consumer_contract/interaction_parser_spec.rb +0 -62
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -121
- data/spec/lib/pact/consumer_contract/interaction_v2_parser_spec.rb +0 -54
- data/spec/lib/pact/consumer_contract/interaction_v3_parser_spec.rb +0 -48
- data/spec/lib/pact/consumer_contract/pact_file_spec.rb +0 -204
- data/spec/lib/pact/consumer_contract/query_hash_spec.rb +0 -154
- data/spec/lib/pact/consumer_contract/query_string_spec.rb +0 -131
- data/spec/lib/pact/consumer_contract/request_spec.rb +0 -486
- data/spec/lib/pact/consumer_contract/response_spec.rb +0 -82
- data/spec/lib/pact/helpers_spec.rb +0 -143
- data/spec/lib/pact/matchers/differ_spec.rb +0 -215
- data/spec/lib/pact/matchers/difference_spec.rb +0 -22
- data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
- data/spec/lib/pact/matchers/extract_diff_messages_spec.rb +0 -78
- data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
- data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -121
- data/spec/lib/pact/matchers/matchers_array_like_spec.rb +0 -222
- data/spec/lib/pact/matchers/matchers_messages_hash_and_array_spec.rb +0 -146
- data/spec/lib/pact/matchers/matchers_messages_mismatched_value_spec.rb +0 -72
- data/spec/lib/pact/matchers/matchers_messages_regexp_spec.rb +0 -103
- data/spec/lib/pact/matchers/matchers_spec.rb +0 -561
- data/spec/lib/pact/matchers/multipart_form_diff_formatter_spec.rb +0 -36
- data/spec/lib/pact/matchers/no_diff_at_index_spec.rb +0 -15
- data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
- data/spec/lib/pact/matchers/type_difference_spec.rb +0 -36
- data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
- data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
- data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -235
- data/spec/lib/pact/matching_rules/extract_spec.rb +0 -216
- data/spec/lib/pact/matching_rules/merge_spec.rb +0 -436
- data/spec/lib/pact/matching_rules/v3/extract_spec.rb +0 -238
- data/spec/lib/pact/matching_rules/v3/merge_spec.rb +0 -485
- data/spec/lib/pact/matching_rules_spec.rb +0 -82
- data/spec/lib/pact/reification_spec.rb +0 -172
- data/spec/lib/pact/shared/dsl_spec.rb +0 -100
- data/spec/lib/pact/shared/form_differ_spec.rb +0 -71
- data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
- data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
- data/spec/lib/pact/shared/multipart_form_differ_spec.rb +0 -49
- data/spec/lib/pact/shared/request_spec.rb +0 -235
- data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
- data/spec/lib/pact/something_like_spec.rb +0 -23
- data/spec/lib/pact/support_spec.rb +0 -9
- data/spec/lib/pact/symbolize_keys_spec.rb +0 -15
- data/spec/lib/pact/term_spec.rb +0 -89
- data/spec/pact_specification/compliance-2.0.rb +0 -66
- data/spec/spec_helper.rb +0 -18
- data/spec/support/a_consumer-a_producer.json +0 -32
- data/spec/support/a_consumer-a_provider.json +0 -32
- data/spec/support/active_support_if_configured.rb +0 -6
- data/spec/support/case-insensitive-response-header-matching.json +0 -21
- data/spec/support/consumer_contract_template.json +0 -24
- data/spec/support/dsl_spec_support.rb +0 -7
- data/spec/support/factories.rb +0 -87
- data/spec/support/generated_index.md +0 -4
- data/spec/support/generated_markdown.md +0 -55
- data/spec/support/interaction_view_model.json +0 -63
- data/spec/support/interaction_view_model_with_terms.json +0 -50
- data/spec/support/markdown_pact.json +0 -48
- data/spec/support/missing_provider_states_output.txt +0 -25
- data/spec/support/options.json +0 -21
- data/spec/support/ruby_version_helpers.rb +0 -23
- data/spec/support/shared_examples_for_request.rb +0 -132
- data/spec/support/spec_support.rb +0 -29
- data/spec/support/stubbing.json +0 -22
- data/spec/support/term.json +0 -48
- data/spec/support/test_app_fail.json +0 -61
- data/spec/support/test_app_pass.json +0 -38
- data/spec/support/test_app_with_right_content_type_differ.json +0 -23
- data/tasks/release.rake +0 -5
- data/tasks/spec.rake +0 -14
@@ -1,36 +0,0 @@
|
|
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
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'pact/matchers/no_diff_at_index'
|
2
|
-
|
3
|
-
module Pact
|
4
|
-
module Matchers
|
5
|
-
describe NoDiffAtIndex do
|
6
|
-
|
7
|
-
describe "#to_json" do
|
8
|
-
it "returns a json string" do
|
9
|
-
expect(NoDiffAtIndex.new.to_json).to eq '"<no difference at this index>"'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact/matchers/regexp_difference'
|
3
|
-
|
4
|
-
module Pact
|
5
|
-
module Matchers
|
6
|
-
describe RegexpDifference do
|
7
|
-
|
8
|
-
context "when a regexp is expected" do
|
9
|
-
|
10
|
-
subject { RegexpDifference.new(/ap/, 'pear').as_json }
|
11
|
-
|
12
|
-
it "indicates that the actual was indended 'to match'" do
|
13
|
-
expect(subject).to eq({:EXPECTED_TO_MATCH => "/ap/", :ACTUAL => "pear"})
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact/matchers/type_difference'
|
3
|
-
require 'support/ruby_version_helpers'
|
4
|
-
|
5
|
-
module Pact
|
6
|
-
module Matchers
|
7
|
-
describe TypeDifference do
|
8
|
-
include RubyVersionHelpers
|
9
|
-
|
10
|
-
describe "#as_json" do
|
11
|
-
|
12
|
-
let(:expected) { ExpectedType.new("Fred") }
|
13
|
-
let(:actual) { ActualType.new(1) }
|
14
|
-
subject { TypeDifference.new expected, actual }
|
15
|
-
|
16
|
-
context "when the actual is a KeyNotFound" do
|
17
|
-
let(:actual) { KeyNotFound.new }
|
18
|
-
let(:expected_hash) { {:EXPECTED_TYPE => "String", :ACTUAL => actual.to_s } }
|
19
|
-
|
20
|
-
it "use the key ACTUAL" do
|
21
|
-
expect(subject.as_json).to eq(expected_hash)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when the actual is an ActualType" do
|
26
|
-
let(:expected_hash) { {:EXPECTED_TYPE => "String", :ACTUAL_TYPE => numeric_type.to_s } }
|
27
|
-
|
28
|
-
it "uses the key ACTUAL_TYPE" do
|
29
|
-
expect(subject.as_json).to eq(expected_hash)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact/matchers/unexpected_index'
|
3
|
-
|
4
|
-
module Pact
|
5
|
-
describe UnexpectedIndex do
|
6
|
-
|
7
|
-
describe "#as_json" do
|
8
|
-
it "returns a string representation of the object" do
|
9
|
-
expect(subject.as_json).to eq subject.to_s
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#to_json" do
|
14
|
-
it "serialises the object to JSON" do
|
15
|
-
expect(subject.to_json).to eq "\"#{subject.to_s}\""
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact/matchers/unexpected_key'
|
3
|
-
|
4
|
-
module Pact
|
5
|
-
describe UnexpectedKey do
|
6
|
-
|
7
|
-
describe "#as_json" do
|
8
|
-
it "returns a string representation of the object" do
|
9
|
-
expect(subject.as_json).to eq subject.to_s
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#to_json" do
|
14
|
-
it "serialises the object to JSON" do
|
15
|
-
expect(subject.to_json).to eq "\"#{subject.to_s}\""
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
@@ -1,235 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact/matchers/unix_diff_formatter'
|
3
|
-
require 'pact/matchers/expected_type'
|
4
|
-
require 'pact/matchers/actual_type'
|
5
|
-
require 'support/ruby_version_helpers'
|
6
|
-
|
7
|
-
module Pact
|
8
|
-
module Matchers
|
9
|
-
describe UnixDiffFormatter do
|
10
|
-
include RubyVersionHelpers
|
11
|
-
|
12
|
-
describe ".call" do
|
13
|
-
|
14
|
-
let(:key_lines_count) { 9 }
|
15
|
-
let(:colour) { false }
|
16
|
-
subject { UnixDiffFormatter.call(diff, {colour: colour}) }
|
17
|
-
|
18
|
-
let(:line_count) { subject.split("\n").size }
|
19
|
-
|
20
|
-
context "when colour = false" do
|
21
|
-
let(:diff) { {thing: {alligator: Difference.new({name: 'Mary'}, "Joe" )}} }
|
22
|
-
it "does not include colour" do
|
23
|
-
expect(subject).to_not include("[0m")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when colour = true" do
|
28
|
-
let(:colour) { true }
|
29
|
-
let(:diff) { {thing: {alligator: Difference.new({name: 'Mary'}, "Joe" )}} }
|
30
|
-
it "uses colour" do
|
31
|
-
expect(subject).to include("[0m")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "with class based matching" do
|
36
|
-
let(:diff) { {thing: TypeDifference.new(ExpectedType.new("fred"), ActualType.new(1))}}
|
37
|
-
let(:output) { <<-EOF
|
38
|
-
{
|
39
|
-
- "thing": String
|
40
|
-
+ "thing": #{numeric_type}
|
41
|
-
}
|
42
|
-
EOF
|
43
|
-
}
|
44
|
-
|
45
|
-
it "displays nicely" do
|
46
|
-
expect(remove_ansicolor subject).to include output
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "with an incorrect value in a hash" do
|
51
|
-
let(:diff) { {thing: {alligator: Difference.new({name: 'Mary'}, "Joe" )}} }
|
52
|
-
|
53
|
-
it "displays '+' next to the unexpected value, and '-' next to the missing one" do
|
54
|
-
expect(subject).to match /alligator/
|
55
|
-
expect(subject).to match /\-.*Mary/
|
56
|
-
expect(subject).to match /\+.*Joe/
|
57
|
-
end
|
58
|
-
|
59
|
-
it "generates the right number of lines, even with ActiveSupport loaded" do
|
60
|
-
expect(line_count).to eq 8 + key_lines_count
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
context "with an incorrect value in an array" do
|
66
|
-
let(:diff) { [NoDiffAtIndex.new, Difference.new({name: 'Mary'}, "Joe"), NoDiffAtIndex.new] }
|
67
|
-
|
68
|
-
it "displays '+' next to the incorrect values and '-' next to the missing ones" do
|
69
|
-
expect(subject).to include "... ,"
|
70
|
-
expect(subject).to match /\-.*{/
|
71
|
-
expect(subject).to match /\-.*}/
|
72
|
-
expect(subject).to match /\-.*Mary/
|
73
|
-
expect(subject).to match /\+.*Joe/
|
74
|
-
expect(subject).to match /\.\.\..*Mary.*Joe.*\.\.\./m
|
75
|
-
end
|
76
|
-
|
77
|
-
it "doesn't display the no difference indicator as a change" do
|
78
|
-
expect(subject).to match(/^\s+... ,$/)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "generates the right number of lines, even with ActiveSupport loaded" do
|
82
|
-
expect(line_count).to eq 8 + key_lines_count
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
context "with a regular expression that was not matched" do
|
88
|
-
let(:regexp) { %r{http://.*/thing/1234} }
|
89
|
-
let(:diff) { {thing: RegexpDifference.new(regexp, "pear")} }
|
90
|
-
|
91
|
-
it "displays the regular expression" do
|
92
|
-
expect(subject).to include(regexp.inspect)
|
93
|
-
expect(subject).to include(regexp.inspect)
|
94
|
-
expect(subject).to match /\-.*thing/
|
95
|
-
expect(subject).to match /\+.*pear/
|
96
|
-
end
|
97
|
-
|
98
|
-
it "does not put quotes around the regular expression" do
|
99
|
-
expect(subject).to match /\/$/
|
100
|
-
expect(subject).to match /: \//
|
101
|
-
end
|
102
|
-
|
103
|
-
it "generates the right number of lines, even with ActiveSupport loaded" do
|
104
|
-
expect(line_count).to eq 4 + key_lines_count
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
context "with a missing key" do
|
110
|
-
|
111
|
-
let(:diff) { {thing: {alligator: Difference.new({name: 'Mary'}, KeyNotFound.new )}} }
|
112
|
-
|
113
|
-
it "it displays '-' next to the missing key and its value" do
|
114
|
-
expect(subject).to match /\-.*{/
|
115
|
-
expect(subject).to match /\-.*}/
|
116
|
-
expect(subject).to match /\-.*alligator/
|
117
|
-
expect(subject).to match /\-.*name/
|
118
|
-
expect(subject).to match /\-.*Mary/
|
119
|
-
end
|
120
|
-
|
121
|
-
it "does not display the missing key in the actual output" do
|
122
|
-
expect(subject).to_not match /\+.*alligator/
|
123
|
-
end
|
124
|
-
|
125
|
-
it "generates the right number of lines, even with ActiveSupport loaded" do
|
126
|
-
expect(line_count).to eq 7 + key_lines_count
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context "with an unexpected key" do
|
131
|
-
let(:diff) { {thing: {alligator: Difference.new(UnexpectedKey.new, {name: 'Mary'} )}} }
|
132
|
-
|
133
|
-
it "displays '+' next to the unexpected key and its value" do
|
134
|
-
expect(subject).to match /\+.*name/
|
135
|
-
expect(subject).to match /\+.*Mary/
|
136
|
-
expect(subject).to match /\+.*alligator/
|
137
|
-
expect(subject).to match /\+.*}/
|
138
|
-
expect(subject).to match /\+.*{/
|
139
|
-
end
|
140
|
-
|
141
|
-
it "does not display the unexpected key in the expected output" do
|
142
|
-
expect(subject).to_not match /\-.*alligator/
|
143
|
-
end
|
144
|
-
|
145
|
-
it "generates the right number of lines, even with ActiveSupport loaded" do
|
146
|
-
expect(line_count).to eq 7 + key_lines_count
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
context "with a missing index" do
|
152
|
-
let(:diff) { [NoDiffAtIndex.new, Difference.new({name: 'Mary'}, IndexNotFound.new)] }
|
153
|
-
|
154
|
-
it "displays '-' next to the missing items" do
|
155
|
-
expect(subject).to match /\-.*Mary/
|
156
|
-
expect(subject).to match /\-.*{/
|
157
|
-
expect(subject).to match /\-.*}/
|
158
|
-
end
|
159
|
-
|
160
|
-
it "does not display IndexNotFound" do
|
161
|
-
expect(subject).to_not match /#{IndexNotFound.new.to_s}/
|
162
|
-
end
|
163
|
-
|
164
|
-
it "generates the right number of lines, even with ActiveSupport loaded" do
|
165
|
-
expect(line_count).to eq 6 + key_lines_count
|
166
|
-
end
|
167
|
-
|
168
|
-
end
|
169
|
-
|
170
|
-
context "with an unexpected index" do
|
171
|
-
let(:diff) { [NoDiffAtIndex.new, Difference.new(UnexpectedIndex.new, {name: 'Mary'})] }
|
172
|
-
let(:diff) { { some_array: [NoDiffAtIndex.new, Difference.new(UnexpectedIndex.new, {name: 'Mary'})]} }
|
173
|
-
|
174
|
-
it "displays '+' next to the unexpected item" do
|
175
|
-
expect(subject).to match /\+.*{/
|
176
|
-
expect(subject).to match /\+.*}/
|
177
|
-
expect(subject).to match /\+.*name/
|
178
|
-
expect(subject).to match /\+.*Mary/
|
179
|
-
end
|
180
|
-
|
181
|
-
it "doesn't mark the 'no difference' as a change" do
|
182
|
-
expect(subject).to include "... ,"
|
183
|
-
expect(subject).to_not match /\-.*\.\.\./
|
184
|
-
expect(subject).to_not match /\+.*\.\.\./
|
185
|
-
end
|
186
|
-
|
187
|
-
it "does not display the UnexpectedIndex" do
|
188
|
-
expect(subject).to_not match UnexpectedIndex.new.to_s
|
189
|
-
end
|
190
|
-
|
191
|
-
it "generates the right number of lines, even with ActiveSupport loaded" do
|
192
|
-
expect(line_count).to eq 8 + key_lines_count
|
193
|
-
end
|
194
|
-
|
195
|
-
end
|
196
|
-
|
197
|
-
context "with 2 unexpected indexes" do
|
198
|
-
let(:diff) { [NoDiffAtIndex.new, Difference.new(UnexpectedIndex.new, {name: 'Mary'}), Difference.new(UnexpectedIndex.new, {name: 'Joe'})] }
|
199
|
-
|
200
|
-
it "displays '+' next to the unexpected item" do
|
201
|
-
expect(subject).to match /\+.*Mary/
|
202
|
-
expect(subject).to match /\+.*Joe/
|
203
|
-
end
|
204
|
-
|
205
|
-
it "does not display the UnexpectedIndex" do
|
206
|
-
expect(subject).to_not match UnexpectedIndex.new.to_s
|
207
|
-
end
|
208
|
-
|
209
|
-
it "generates the right number of lines, even with ActiveSupport loaded" do
|
210
|
-
expect(line_count).to eq 9 + key_lines_count
|
211
|
-
end
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
context "when the explanation should be included (default)" do
|
216
|
-
let(:diff) { {thing: {alligator: Difference.new({name: 'Mary'}, "Joe" )}} }
|
217
|
-
subject { UnixDiffFormatter.call(diff, {colour: colour}) }
|
218
|
-
|
219
|
-
it "appends the explanation" do
|
220
|
-
expect(subject).to include ("Key:")
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context "when the explanation should not be included" do
|
225
|
-
let(:diff) { {thing: {alligator: Difference.new({name: 'Mary'}, "Joe" )}} }
|
226
|
-
subject { UnixDiffFormatter.call(diff, {colour: colour, include_explanation: false}) }
|
227
|
-
|
228
|
-
it "does not append the explanation" do
|
229
|
-
expect(subject).to_not include ("Key:")
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
@@ -1,216 +0,0 @@
|
|
1
|
-
require 'pact/matching_rules/extract'
|
2
|
-
require 'pact/something_like'
|
3
|
-
require 'pact/array_like'
|
4
|
-
require 'pact/term'
|
5
|
-
|
6
|
-
module Pact
|
7
|
-
module MatchingRules
|
8
|
-
describe Extract do
|
9
|
-
|
10
|
-
describe ".call" do
|
11
|
-
|
12
|
-
subject { Extract.call(matchable) }
|
13
|
-
|
14
|
-
context "with a Pact::SomethingLike" do
|
15
|
-
let(:matchable) do
|
16
|
-
{
|
17
|
-
body: Pact::SomethingLike.new(foo: 'bar', alligator: { name: 'Mary' })
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:rules) do
|
22
|
-
{
|
23
|
-
"$.body" => {"match" => "type"}
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
it "creates a rule that matches by type" do
|
28
|
-
expect(subject).to eq rules
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "with a Pact::Term" do
|
33
|
-
let(:matchable) do
|
34
|
-
{
|
35
|
-
body: {
|
36
|
-
alligator: {
|
37
|
-
name: Pact::Term.new(generate: 'Mary', matcher: /.*a/)
|
38
|
-
}
|
39
|
-
}
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
let(:rules) do
|
44
|
-
{
|
45
|
-
"$.body.alligator.name" => {"match" => "regex", "regex" => ".*a"}
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
it "creates a rule that matches by regex" do
|
50
|
-
expect(subject).to eq rules
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "with a Pact::SomethingLike containing a Term" do
|
55
|
-
let(:matchable) do
|
56
|
-
{
|
57
|
-
body: Pact::SomethingLike.new(
|
58
|
-
foo: 'bar',
|
59
|
-
alligator: { name: Pact::Term.new(generate: 'Mary', matcher: /.*a/) }
|
60
|
-
)
|
61
|
-
}
|
62
|
-
end
|
63
|
-
|
64
|
-
let(:rules) do
|
65
|
-
{
|
66
|
-
"$.body" => {"match" => "type"},
|
67
|
-
"$.body.alligator.name" => {"match" => "regex", "regex"=>".*a"},
|
68
|
-
}
|
69
|
-
end
|
70
|
-
|
71
|
-
it "the match:regex overrides the match:type" do
|
72
|
-
expect(subject).to eq rules
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "with a Pact::SomethingLike containing an array" do
|
77
|
-
let(:matchable) do
|
78
|
-
{
|
79
|
-
body: Pact::SomethingLike.new(
|
80
|
-
alligators: [
|
81
|
-
{name: 'Mary'},
|
82
|
-
{name: 'Betty'}
|
83
|
-
]
|
84
|
-
)
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
let(:rules) do
|
89
|
-
{
|
90
|
-
"$.body" => {"match" => "type"}
|
91
|
-
}
|
92
|
-
end
|
93
|
-
|
94
|
-
it "lists a rule for each item" do
|
95
|
-
expect(subject).to eq rules
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "with an ArrayLike" do
|
100
|
-
let(:matchable) do
|
101
|
-
{
|
102
|
-
body: {
|
103
|
-
alligators: Pact::ArrayLike.new(
|
104
|
-
name: 'Fred'
|
105
|
-
)
|
106
|
-
}
|
107
|
-
}
|
108
|
-
end
|
109
|
-
|
110
|
-
let(:rules) do
|
111
|
-
{
|
112
|
-
"$.body.alligators" => {"min" => 1},
|
113
|
-
"$.body.alligators[*].*" => {"match" => "type"}
|
114
|
-
}
|
115
|
-
end
|
116
|
-
|
117
|
-
it "lists a rule for all items" do
|
118
|
-
expect(subject).to eq rules
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "with an ArrayLike with a Pact::Term inside" do
|
123
|
-
let(:matchable) do
|
124
|
-
{
|
125
|
-
body: {
|
126
|
-
alligators: Pact::ArrayLike.new(
|
127
|
-
name: 'Fred',
|
128
|
-
phoneNumber: Pact::Term.new(generate: '1234567', matcher: /\d+/)
|
129
|
-
)
|
130
|
-
}
|
131
|
-
}
|
132
|
-
end
|
133
|
-
|
134
|
-
let(:rules) do
|
135
|
-
{
|
136
|
-
"$.body.alligators" => {"min" => 1},
|
137
|
-
"$.body.alligators[*].*" => {"match" => "type"},
|
138
|
-
"$.body.alligators[*].phoneNumber" => {"match" => "regex", "regex" => "\\d+"}
|
139
|
-
}
|
140
|
-
end
|
141
|
-
|
142
|
-
it "lists a rule that specifies that the regular expression must match" do
|
143
|
-
expect(subject).to eq rules
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context "with a Pact::QueryString containing a Pact::Term" do
|
148
|
-
let(:matchable) do
|
149
|
-
{
|
150
|
-
query: Pact::QueryString.new(Pact::Term.new(generate: 'foobar', matcher: /foo/))
|
151
|
-
}
|
152
|
-
end
|
153
|
-
|
154
|
-
let(:rules) do
|
155
|
-
{
|
156
|
-
"$.query" => {"match" => "regex", "regex" => "foo"}
|
157
|
-
}
|
158
|
-
end
|
159
|
-
|
160
|
-
it "lists a rule that specifies that the regular expression must match" do
|
161
|
-
expect(subject).to eq rules
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context "with a Pact::QueryHash containing a Pact::Term" do
|
166
|
-
let(:matchable) do
|
167
|
-
{
|
168
|
-
query: Pact::QueryHash.new(bar: Pact::Term.new(generate: 'foobar', matcher: /foo/))
|
169
|
-
}
|
170
|
-
end
|
171
|
-
|
172
|
-
let(:rules) do
|
173
|
-
{
|
174
|
-
"$.query.bar[0]" => {"match" => "regex", "regex" => "foo"}
|
175
|
-
}
|
176
|
-
end
|
177
|
-
|
178
|
-
it "lists a rule that specifies that the regular expression must match" do
|
179
|
-
expect(subject).to eq rules
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "with no special matching" do
|
184
|
-
let(:matchable) do
|
185
|
-
{
|
186
|
-
body: { alligator: { name: 'Mary' } }
|
187
|
-
}
|
188
|
-
end
|
189
|
-
|
190
|
-
let(:rules) do
|
191
|
-
{}
|
192
|
-
end
|
193
|
-
|
194
|
-
|
195
|
-
it "does not create any rules" do
|
196
|
-
expect(subject).to eq rules
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context "with a key containing a dot" do
|
201
|
-
let(:matchable) do
|
202
|
-
{
|
203
|
-
"key" => {
|
204
|
-
"key.with.dots" => Pact::SomethingLike.new("foo")
|
205
|
-
}
|
206
|
-
}
|
207
|
-
end
|
208
|
-
|
209
|
-
it "uses square brackets notation for the key with dots" do
|
210
|
-
expect(subject.keys).to include "$.key['key.with.dots']"
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|