pact-support 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +29 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +80 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +4 -0
- data/lib/pact/configuration.rb +164 -0
- data/lib/pact/consumer/request.rb +27 -0
- data/lib/pact/consumer_contract.rb +1 -0
- data/lib/pact/consumer_contract/consumer_contract.rb +114 -0
- data/lib/pact/consumer_contract/file_name.rb +19 -0
- data/lib/pact/consumer_contract/headers.rb +51 -0
- data/lib/pact/consumer_contract/interaction.rb +73 -0
- data/lib/pact/consumer_contract/pact_file.rb +24 -0
- data/lib/pact/consumer_contract/request.rb +73 -0
- data/lib/pact/consumer_contract/response.rb +51 -0
- data/lib/pact/consumer_contract/service_consumer.rb +28 -0
- data/lib/pact/consumer_contract/service_provider.rb +28 -0
- data/lib/pact/logging.rb +14 -0
- data/lib/pact/matchers.rb +1 -0
- data/lib/pact/matchers/actual_type.rb +16 -0
- data/lib/pact/matchers/base_difference.rb +37 -0
- data/lib/pact/matchers/differ.rb +153 -0
- data/lib/pact/matchers/difference.rb +13 -0
- data/lib/pact/matchers/difference_indicator.rb +26 -0
- data/lib/pact/matchers/embedded_diff_formatter.rb +62 -0
- data/lib/pact/matchers/expected_type.rb +35 -0
- data/lib/pact/matchers/index_not_found.rb +15 -0
- data/lib/pact/matchers/list_diff_formatter.rb +101 -0
- data/lib/pact/matchers/matchers.rb +139 -0
- data/lib/pact/matchers/no_diff_indicator.rb +18 -0
- data/lib/pact/matchers/regexp_difference.rb +13 -0
- data/lib/pact/matchers/type_difference.rb +16 -0
- data/lib/pact/matchers/unexpected_index.rb +11 -0
- data/lib/pact/matchers/unexpected_key.rb +11 -0
- data/lib/pact/matchers/unix_diff_formatter.rb +114 -0
- data/lib/pact/reification.rb +28 -0
- data/lib/pact/rspec.rb +53 -0
- data/lib/pact/shared/active_support_support.rb +51 -0
- data/lib/pact/shared/dsl.rb +76 -0
- data/lib/pact/shared/jruby_support.rb +18 -0
- data/lib/pact/shared/json_differ.rb +15 -0
- data/lib/pact/shared/key_not_found.rb +15 -0
- data/lib/pact/shared/null_expectation.rb +31 -0
- data/lib/pact/shared/request.rb +97 -0
- data/lib/pact/shared/text_differ.rb +14 -0
- data/lib/pact/something_like.rb +49 -0
- data/lib/pact/support.rb +9 -0
- data/lib/pact/support/version.rb +5 -0
- data/lib/pact/symbolize_keys.rb +12 -0
- data/lib/pact/term.rb +85 -0
- data/lib/tasks/pact.rake +29 -0
- data/pact-support.gemspec +35 -0
- data/spec/lib/pact/consumer/request_spec.rb +25 -0
- data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +58 -0
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +141 -0
- data/spec/lib/pact/consumer_contract/headers_spec.rb +107 -0
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +151 -0
- data/spec/lib/pact/consumer_contract/request_spec.rb +329 -0
- data/spec/lib/pact/consumer_contract/response_spec.rb +73 -0
- data/spec/lib/pact/matchers/differ_spec.rb +215 -0
- data/spec/lib/pact/matchers/difference_spec.rb +22 -0
- data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +90 -0
- data/spec/lib/pact/matchers/index_not_found_spec.rb +21 -0
- data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +120 -0
- data/spec/lib/pact/matchers/matchers_spec.rb +500 -0
- data/spec/lib/pact/matchers/regexp_difference_spec.rb +20 -0
- data/spec/lib/pact/matchers/type_difference_spec.rb +34 -0
- data/spec/lib/pact/matchers/unexpected_index_spec.rb +20 -0
- data/spec/lib/pact/matchers/unexpected_key_spec.rb +20 -0
- data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +216 -0
- data/spec/lib/pact/reification_spec.rb +67 -0
- data/spec/lib/pact/shared/dsl_spec.rb +86 -0
- data/spec/lib/pact/shared/json_differ_spec.rb +36 -0
- data/spec/lib/pact/shared/key_not_found_spec.rb +20 -0
- data/spec/lib/pact/shared/request_spec.rb +196 -0
- data/spec/lib/pact/shared/text_differ_spec.rb +54 -0
- data/spec/lib/pact/something_like_spec.rb +21 -0
- data/spec/lib/pact/term_spec.rb +89 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/a_consumer-a_producer.json +32 -0
- data/spec/support/a_consumer-a_provider.json +32 -0
- data/spec/support/active_support_if_configured.rb +6 -0
- data/spec/support/case-insensitive-response-header-matching.json +21 -0
- data/spec/support/consumer_contract_template.json +24 -0
- data/spec/support/dsl_spec_support.rb +7 -0
- data/spec/support/factories.rb +82 -0
- data/spec/support/generated_index.md +4 -0
- data/spec/support/generated_markdown.md +55 -0
- data/spec/support/interaction_view_model.json +63 -0
- data/spec/support/interaction_view_model_with_terms.json +50 -0
- data/spec/support/markdown_pact.json +48 -0
- data/spec/support/missing_provider_states_output.txt +25 -0
- data/spec/support/options.json +21 -0
- data/spec/support/shared_examples_for_request.rb +94 -0
- data/spec/support/spec_support.rb +20 -0
- data/spec/support/stubbing.json +22 -0
- data/spec/support/term.json +48 -0
- data/spec/support/test_app_fail.json +61 -0
- data/spec/support/test_app_pass.json +38 -0
- data/spec/support/test_app_with_right_content_type_differ.json +23 -0
- data/tasks/spec.rake +6 -0
- metadata +401 -0
@@ -0,0 +1,500 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pact/matchers'
|
3
|
+
require 'pact/consumer_contract/headers'
|
4
|
+
|
5
|
+
module Pact::Matchers
|
6
|
+
|
7
|
+
describe Pact::Matchers do
|
8
|
+
include Pact::Matchers
|
9
|
+
|
10
|
+
# TODO this is an integration test
|
11
|
+
describe 'matching headers' do
|
12
|
+
let(:expected) { Pact::Headers.new('Content-Type' => 'application/hippo')}
|
13
|
+
|
14
|
+
context "when the headers match in a case insensitive way" do
|
15
|
+
|
16
|
+
context "when the values match" do
|
17
|
+
let(:actual) { Pact::Headers.new('CONTENT-TYPE' => 'application/hippo')}
|
18
|
+
it "returns an empty diff" do
|
19
|
+
expect(diff(expected, actual)).to be_empty
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when the header values do not match" do
|
24
|
+
let(:actual) { Pact::Headers.new('CONTENT-TYPE' => 'application/alligator')}
|
25
|
+
let(:difference) { {"Content-Type" => Difference.new('application/hippo', 'application/alligator')} }
|
26
|
+
it "returns the diff" do
|
27
|
+
expect(diff(expected, actual)).to eq difference
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when the headers do not match" do
|
33
|
+
|
34
|
+
let(:actual) { Pact::Headers.new('Content-Length' => '1')}
|
35
|
+
let(:difference) { {"Content-Type" => Difference.new('application/hippo', Pact::KeyNotFound.new)} }
|
36
|
+
it "returns a diff" do
|
37
|
+
expect(diff(expected, actual)).to eq difference
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'matching with something like' do
|
45
|
+
|
46
|
+
context 'when the actual is something like the expected' do
|
47
|
+
let(:expected) { Pact::SomethingLike.new( { a: 1 } ) }
|
48
|
+
let(:actual) { { a: 2} }
|
49
|
+
|
50
|
+
it 'returns an empty diff' do
|
51
|
+
expect(diff(expected, actual)).to eq({})
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'option {allow_unexpected_keys: false}' do
|
59
|
+
context "when an unexpected key is found" do
|
60
|
+
let(:expected) { {:a => 1} }
|
61
|
+
let(:actual) { {:a => 1, :b => 2} }
|
62
|
+
let(:difference) { {:b => Difference.new(Pact::UnexpectedKey.new, 2 )} }
|
63
|
+
it "returns it in the diff" do
|
64
|
+
expect(diff(expected, actual, allow_unexpected_keys: false)).to eq difference
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "expecting key to be present with nil value and not finding key" do
|
70
|
+
let(:expected) { {a: nil} }
|
71
|
+
let(:actual) { {} }
|
72
|
+
let(:difference) { {a: Difference.new(nil, Pact::KeyNotFound.new )} }
|
73
|
+
it "returns the key in the diff" do
|
74
|
+
expect(diff(expected, actual)).to eq difference
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "expecting a string matching a regexp and not finding key" do
|
79
|
+
let(:expected) { {a: /b/} }
|
80
|
+
let(:actual) { {} }
|
81
|
+
let(:difference) { {:a=> RegexpDifference.new(/b/, Pact::KeyNotFound.new) } }
|
82
|
+
it "returns the diff" do
|
83
|
+
expect(diff(expected, actual)).to eq difference
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'type_diff' do
|
88
|
+
let(:expected) {
|
89
|
+
{a: 'a string', b: 1, c: nil, d: [{e: 'thing'}], f: {g: 10}, h: false}
|
90
|
+
}
|
91
|
+
|
92
|
+
context "when the classes match" do
|
93
|
+
let(:actual) { {a: 'another string', b: 2, c: nil, d: [{e: 'something'}], f: {g: 100}, h: true} }
|
94
|
+
let(:difference) { {} }
|
95
|
+
it "returns an empty hash" do
|
96
|
+
expect(type_diff(expected, actual)).to eq difference
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "when a key is not found" do
|
101
|
+
let(:actual) { {a: 'blah'} }
|
102
|
+
let(:expected) { {b: 'blah'} }
|
103
|
+
let(:difference) { {:b=>TypeDifference.new(Pact::ExpectedType.new("blah"), Pact::KeyNotFound.new)} }
|
104
|
+
it "returns the difference" do
|
105
|
+
expect(type_diff(expected, actual)).to eq difference
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when a number is expected" do
|
110
|
+
let(:expected) { {a: 1} }
|
111
|
+
let(:difference) { {a: TypeDifference.new(Pact::ExpectedType.new(1) , Pact::ActualType.new('a string'))} }
|
112
|
+
|
113
|
+
context "and a string is found" do
|
114
|
+
let(:actual) { {a: 'a string'}}
|
115
|
+
it "returns the diff" do
|
116
|
+
expect(type_diff(expected, actual)).to eq difference
|
117
|
+
end
|
118
|
+
end
|
119
|
+
context "and nil is found" do
|
120
|
+
let(:actual) { {a: nil}}
|
121
|
+
let(:difference ) { {a: TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new(nil)) } }
|
122
|
+
it "returns the diff" do
|
123
|
+
expect(type_diff(expected, actual)).to eq difference
|
124
|
+
end
|
125
|
+
end
|
126
|
+
context "and a hash is found" do
|
127
|
+
let(:actual) { {a: {b: 1}} }
|
128
|
+
let(:difference) { {:a=>TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new({:b=>1})) } }
|
129
|
+
it "returns the diff" do
|
130
|
+
expect(type_diff(expected, actual)).to eq difference
|
131
|
+
end
|
132
|
+
end
|
133
|
+
context "and an array is found" do
|
134
|
+
let(:actual) { {a: [1] } }
|
135
|
+
let(:difference) { {:a=>TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new([1]))}}
|
136
|
+
it "returns the diff" do
|
137
|
+
expect(type_diff(expected, actual)).to eq difference
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "when an array is expected" do
|
143
|
+
let(:expected) { [{name: 'Fred'}, {name: 'Mary'}] }
|
144
|
+
context "when an item with differing class values is found" do
|
145
|
+
let(:actual) { [{name: 'Fred'}, {name: 1}] }
|
146
|
+
let(:difference) { [
|
147
|
+
Pact::Matchers::NO_DIFF_INDICATOR,
|
148
|
+
{:name =>
|
149
|
+
TypeDifference.new(Pact::ExpectedType.new("Mary"), Pact::ActualType.new(1))
|
150
|
+
}
|
151
|
+
]
|
152
|
+
}
|
153
|
+
it "returns the diff" do
|
154
|
+
expect(type_diff(expected, actual)).to eq difference
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
context "when nil is expected" do
|
161
|
+
let(:expected) { {a: nil} }
|
162
|
+
context "and a string is found" do
|
163
|
+
let(:actual) { {a: 'a string'} }
|
164
|
+
let(:difference) { {:a=>TypeDifference.new(Pact::ExpectedType.new(nil), Pact::ActualType.new("a string")) } }
|
165
|
+
it "returns the diff" do
|
166
|
+
expect(type_diff(expected, actual)).to eq difference
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "when a term is expected" do
|
172
|
+
let(:expected) { {a: Pact::Term.new(:matcher => /p/, :generate => 'apple')} }
|
173
|
+
context "and a non matching string is found" do
|
174
|
+
let(:actual) { {a: 'banana'} }
|
175
|
+
let(:difference) { {:a=>Pact::Matchers::RegexpDifference.new(/p/,"banana")} }
|
176
|
+
it "returns the diff" do
|
177
|
+
expect(type_diff(expected, actual)).to eq difference
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "when a term is expected inside a missing hash" do
|
183
|
+
let(:expected) { {a: {b: Pact::Term.new(:matcher => /p/, :generate => 'apple')}} }
|
184
|
+
context "and a non matching value is found" do
|
185
|
+
let(:actual) { {a: nil} }
|
186
|
+
let(:difference) { {a: Difference.new({b: /p/}, nil)} }
|
187
|
+
it "returns the diff with the regexp unpacked" do
|
188
|
+
expect(type_diff(expected, actual)).to eq difference
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context "when unexpected keys are allowed" do
|
194
|
+
let(:expected) { { a: 'b' } }
|
195
|
+
let(:actual) { {a: 'c', d: 'e'} }
|
196
|
+
let(:difference) { {} }
|
197
|
+
it "returns the diff" do
|
198
|
+
expect(type_diff(expected, actual, allow_unexpected_keys: true)).to eq difference
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "when unexpected keys are not allowed" do
|
203
|
+
let(:expected) { { a: 'b' } }
|
204
|
+
let(:actual) { {a: 'c', d: 'e'} }
|
205
|
+
let(:difference) { {d: Difference.new(Pact::UnexpectedKey.new, 'e')} }
|
206
|
+
it "returns the diff" do
|
207
|
+
expect(type_diff(expected, actual, allow_unexpected_keys: false)).to eq difference
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe 'diffing' do
|
213
|
+
|
214
|
+
context "when expected is longer than the actual" do
|
215
|
+
subject { [1,2,3] }
|
216
|
+
let(:actual) { [1,2]}
|
217
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(3, Pact::IndexNotFound.new)] }
|
218
|
+
it 'returns the diff' do
|
219
|
+
expect(diff(subject, actual)).to eq(difference)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "when the different index is in the middle of an array" do
|
224
|
+
subject { [1,2,3] }
|
225
|
+
let(:actual) { [1,7,3]}
|
226
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(2, 7), Pact::Matchers::NO_DIFF_INDICATOR] }
|
227
|
+
it 'returns the diff' do
|
228
|
+
expect(diff(subject, actual)).to eq(difference)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context "when actual array is longer than the expected" do
|
233
|
+
subject { [1] }
|
234
|
+
let(:actual) { [1,2]}
|
235
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(Pact::UnexpectedIndex.new, 2)] }
|
236
|
+
it 'returns the diff' do
|
237
|
+
expect(diff(subject, actual)).to eq(difference)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'where an expected value is a non-empty string' do
|
242
|
+
|
243
|
+
subject { {:a => 'a', :b => 'b'} }
|
244
|
+
|
245
|
+
context 'and the actual value is an empty string' do
|
246
|
+
|
247
|
+
let(:actual) { {:a => 'a', :b => ''} }
|
248
|
+
|
249
|
+
it 'includes this in the diff' do
|
250
|
+
expect(diff(subject, actual)).to eq({:b => Difference.new('b', '')})
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
context "when the expected value is a hash" do
|
258
|
+
subject { {a: 'b'} }
|
259
|
+
context "when the actual value is an array" do
|
260
|
+
let(:actual) { [1] }
|
261
|
+
let(:difference) { Difference.new(subject, actual) }
|
262
|
+
it "should return the diff" do
|
263
|
+
expect(diff(subject, actual)).to eq(difference)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
context "when the actual value is an hash" do
|
267
|
+
let(:actual) { {b: 'c'} }
|
268
|
+
let(:difference) { { a: Difference.new("b",Pact::KeyNotFound.new)} }
|
269
|
+
it "should return the diff" do
|
270
|
+
expect(diff(subject, actual)).to eq(difference)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
context "when the actual value is an number" do
|
274
|
+
let(:actual) { 1 }
|
275
|
+
let(:difference) { Difference.new({a: "b"}, 1) }
|
276
|
+
it "should return the diff" do
|
277
|
+
expect(diff(subject, actual)).to eq(difference)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
context "when the actual value is a string" do
|
281
|
+
let(:actual) { "Thing" }
|
282
|
+
let(:difference) { Difference.new(subject, actual) }
|
283
|
+
it "should return the diff" do
|
284
|
+
expect(diff(subject, actual)).to eq(difference)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
context "when the actual value is the same" do
|
288
|
+
let (:actual) { {a: 'b'} }
|
289
|
+
it "should return an empty hash" do
|
290
|
+
expect(diff(subject, actual)).to eq({})
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context "when the expected value is an array" do
|
296
|
+
subject { [1] }
|
297
|
+
context "when the actual value is an array" do
|
298
|
+
let(:actual) { [2] }
|
299
|
+
let(:difference) { [Difference.new(1, 2)] }
|
300
|
+
it "should return the diff" do
|
301
|
+
expect(diff(subject, actual)).to eq difference
|
302
|
+
end
|
303
|
+
end
|
304
|
+
context "when the actual value is an hash" do
|
305
|
+
let(:actual) { {b: 'c'} }
|
306
|
+
let(:difference) { Difference.new(subject, actual) }
|
307
|
+
it "should return the diff" do
|
308
|
+
expect(diff(subject, actual)).to eq(difference)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
context "when the actual value is an number" do
|
312
|
+
let(:actual) { 1 }
|
313
|
+
let(:difference) { Difference.new(subject, actual) }
|
314
|
+
it "should return the diff" do
|
315
|
+
expect(diff(subject, actual)).to eq(difference)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
context "when the actual value is a string" do
|
319
|
+
let(:actual) { "Thing" }
|
320
|
+
let(:difference) { Difference.new(subject, actual) }
|
321
|
+
it "should return the diff" do
|
322
|
+
expect(diff(subject, actual)).to eq(difference)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
context "when the actual value is the same" do
|
326
|
+
let (:actual) { [1] }
|
327
|
+
it "should return an empty hash" do
|
328
|
+
expect(diff(subject, actual)).to eql({})
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "when the expected value is a string" do
|
334
|
+
subject { "Thing"}
|
335
|
+
context "when the actual value is an array" do
|
336
|
+
let(:actual) { [2] }
|
337
|
+
let(:difference) { Difference.new(subject, actual) }
|
338
|
+
it "should return the diff" do
|
339
|
+
expect(diff(subject, actual)).to eq(difference)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
context "when the actual value is an hash" do
|
343
|
+
let(:actual) { {b: 'c'} }
|
344
|
+
let(:difference) { Difference.new(subject, actual) }
|
345
|
+
it "should return the diff" do
|
346
|
+
expect(diff(subject, actual)).to eq(difference)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
context "when the actual value is an number" do
|
350
|
+
let(:actual) { 1 }
|
351
|
+
let(:difference) { Difference.new(subject, actual) }
|
352
|
+
it "should return the diff" do
|
353
|
+
expect(diff(subject, actual)).to eq(difference)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
context "when the actual value is a string" do
|
357
|
+
let(:actual) { "Another Thing" }
|
358
|
+
let(:difference) { Difference.new(subject, actual) }
|
359
|
+
it "should return the diff" do
|
360
|
+
expect(diff(subject, actual)).to eq(difference)
|
361
|
+
end
|
362
|
+
end
|
363
|
+
context "when the actual value is the same" do
|
364
|
+
let (:actual) { "Thing" }
|
365
|
+
it "should return an empty hash" do
|
366
|
+
expect(diff(subject, actual)).to eq({})
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context "when the expected value is a number" do
|
372
|
+
subject { 1 }
|
373
|
+
let(:difference) { Difference.new(subject, actual) }
|
374
|
+
context "when the actual value is an array" do
|
375
|
+
let(:actual) { [2] }
|
376
|
+
it "should return the diff" do
|
377
|
+
expect(diff(subject, actual)).to eq(difference)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
context "when the actual value is an hash" do
|
381
|
+
let(:actual) { {b: 'c'} }
|
382
|
+
it "should return the diff" do
|
383
|
+
expect(diff(subject, actual)).to eq(difference)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
context "when the actual value is an number" do
|
387
|
+
let(:actual) { 2 }
|
388
|
+
it "should return the diff" do
|
389
|
+
expect(diff(subject, actual)).to eq(difference)
|
390
|
+
end
|
391
|
+
end
|
392
|
+
context "when the actual value is a string" do
|
393
|
+
let(:actual) { "Another Thing" }
|
394
|
+
it "should return the diff" do
|
395
|
+
expect(diff(subject, actual)).to eq(difference)
|
396
|
+
end
|
397
|
+
end
|
398
|
+
context "when the actual value is the same" do
|
399
|
+
let (:actual) { 1 }
|
400
|
+
it "should return an empty hash" do
|
401
|
+
expect(diff(subject, actual)).to eq({})
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context "when the expected value is a String matcher" do
|
407
|
+
|
408
|
+
end
|
409
|
+
|
410
|
+
context "when the expected value is a Number matcher" do
|
411
|
+
|
412
|
+
end
|
413
|
+
context "when the expected value is an array with a matcher" do
|
414
|
+
|
415
|
+
end
|
416
|
+
context "when the expected value is a hash with a matcher" do
|
417
|
+
|
418
|
+
end
|
419
|
+
|
420
|
+
context "when an expected value is nil but not nil is found" do
|
421
|
+
subject { {a: nil} }
|
422
|
+
let(:actual) { {a: 'blah'} }
|
423
|
+
let(:difference) { {:a=>Difference.new(nil, "blah")} }
|
424
|
+
it "should return the diff" do
|
425
|
+
expect(diff(subject, actual)).to eq(difference)
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
context "a deep mismatch" do
|
430
|
+
subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/, generate: 'apple')}}, f: 1, g: {h: 99}} }
|
431
|
+
let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} }
|
432
|
+
let(:difference) { {:a=>{:d=>{:e=> RegexpDifference.new(/a/, "food")}},
|
433
|
+
:f=> Difference.new(1, "thing"),
|
434
|
+
:g=>Difference.new({:h=>99}, Pact::KeyNotFound.new)} }
|
435
|
+
|
436
|
+
it 'should return the diff' do
|
437
|
+
expect(diff(subject, actual)).to eq(difference)
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
context "where a Pact::Term is found that matches the actual value" do
|
443
|
+
subject { {:a => Pact::Term.new(:matcher => /a/, :generate => 'apple')} }
|
444
|
+
let(:actual) { {:a => "apple" } }
|
445
|
+
|
446
|
+
it 'does not include this in the diff' do
|
447
|
+
expect(diff(subject, actual)).to eq({})
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
context "where an array is expected at a key inside a hash, but a hash is found" do
|
452
|
+
subject { {:a => [1,2,3]} }
|
453
|
+
let(:actual) { {:a => {:b => 1} } }
|
454
|
+
|
455
|
+
it 'includes this in the diff' do
|
456
|
+
expect(diff(subject, actual)).to eq({:a => Difference.new([1,2,3], {:b => 1})})
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
context "where an array is expected, but a hash is found" do
|
461
|
+
subject { {:a => :b} }
|
462
|
+
let(:actual) { [4,5,6] }
|
463
|
+
|
464
|
+
it 'includes this in the diff' do
|
465
|
+
expect(diff(subject, actual)).to eq(Difference.new({:a => :b}, [4,5,6] ))
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
context "where a hash is expected, but array is found" do
|
470
|
+
subject { [4,5,6] }
|
471
|
+
let(:actual) { {:a => :b} }
|
472
|
+
|
473
|
+
it 'includes this in the diff' do
|
474
|
+
expect(diff(subject, actual)).to eq(Difference.new([4,5,6],{:a => :b}))
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
context "when two different arrays are found" do
|
479
|
+
subject { [4,5,6] }
|
480
|
+
let(:actual) { [4,6,7] }
|
481
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(5, 6), Difference.new(6, 7)] }
|
482
|
+
|
483
|
+
it 'includes this in the diff' do
|
484
|
+
expect(diff(subject, actual)).to eq(difference)
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
context "when an array that matches the Pact::Term is found" do
|
489
|
+
subject { [Pact::Term.new(:matcher => /4/, :generate => '4'),"5","6"] }
|
490
|
+
let(:actual) { ["4","5","6"] }
|
491
|
+
|
492
|
+
it 'includes this in the diff' do
|
493
|
+
expect(diff(subject, actual)).to eq({})
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
end
|
498
|
+
|
499
|
+
end
|
500
|
+
end
|