pact 1.0.26 → 1.0.27
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.
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +5 -3
- data/lib/pact/consumer/mock_service/interaction_mismatch.rb +16 -3
- data/lib/pact/consumer/mock_service/interaction_replay.rb +3 -8
- data/lib/pact/consumer_contract/interaction.rb +4 -0
- data/lib/pact/matchers/diff_decorator.rb +84 -0
- data/lib/pact/matchers/matchers.rb +50 -7
- data/lib/pact/provider.rb +1 -0
- data/lib/pact/provider/pact_spec_runner.rb +2 -0
- data/lib/pact/provider/print_missing_provider_states.rb +30 -0
- data/lib/pact/provider/provider_state_proxy.rb +35 -0
- data/lib/pact/provider/rspec.rb +2 -2
- data/lib/pact/provider/test_methods.rb +3 -18
- data/lib/pact/provider/world.rb +19 -0
- data/lib/pact/templates/provider_state.erb +15 -0
- data/lib/pact/version.rb +1 -1
- data/{scratchpad.txt → scratchpad.rb} +17 -1
- data/spec/integration/consumer_spec.rb +2 -2
- data/spec/lib/pact/matchers/diff_decorator_spec.rb +80 -0
- data/spec/lib/pact/matchers/matchers_spec.rb +313 -308
- data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +19 -0
- data/spec/lib/pact/provider/provider_state_proxy_spec.rb +60 -0
- data/spec/lib/pact/provider/world_spec.rb +33 -0
- data/spec/support/missing_provider_states_output.txt +25 -0
- metadata +20 -7
- data/spec/lib/pact/provider/test_methods_spec.rb +0 -20
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Pact
|
|
2
|
+
|
|
3
|
+
def self.world
|
|
4
|
+
@world ||= Pact::Provider::World.new
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module Provider
|
|
8
|
+
class World
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def provider_states
|
|
14
|
+
@provider_states_proxy ||= Pact::Provider::ProviderStateProxy.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
Could not find one or more provider states.
|
|
3
|
+
Have you required the provider states file for this consumer in your pact_helper.rb?
|
|
4
|
+
If you have not yet defined these states, here is a template:
|
|
5
|
+
<% consumers.keys.each do | consumer_name | %>
|
|
6
|
+
Pact.provider_states_for "<%= consumer_name %>" do
|
|
7
|
+
<% consumers[consumer_name].each do | provider_state | %>
|
|
8
|
+
provider_state "<%= provider_state %>" do
|
|
9
|
+
set_up do
|
|
10
|
+
# Your set up code goes here
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
<% end %>
|
|
14
|
+
end
|
|
15
|
+
<% end %>
|
data/lib/pact/version.rb
CHANGED
|
@@ -29,8 +29,24 @@ Need a way to specify a literal empty hash, rather than a hash that matches anyt
|
|
|
29
29
|
{:something => actual({}) }
|
|
30
30
|
{:something => empty_hash }
|
|
31
31
|
|
|
32
|
-
Slightly unintuitive behaviour: {} matches any hash, but [] only matches an empty array (or does now we've changed the code). Should [] match any array? How do we then specify an empty array?
|
|
32
|
+
# Slightly unintuitive behaviour: {} matches any hash, but [] only matches an empty array (or does now we've changed the code). Should [] match any array? How do we then specify an empty array?
|
|
33
33
|
|
|
34
34
|
{:something => literal([]) }
|
|
35
35
|
{:something => actual([]) }
|
|
36
36
|
{:something => empty_array }
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Pact.build do
|
|
40
|
+
{
|
|
41
|
+
status: 200,
|
|
42
|
+
headers: exactly({
|
|
43
|
+
|
|
44
|
+
}),
|
|
45
|
+
body: including({
|
|
46
|
+
age: literal('12'),
|
|
47
|
+
phoneNumber: example("0415 134 234", /\d{4} \d{3} \d{3}/),
|
|
48
|
+
favouriteColors:
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
end
|
|
@@ -57,8 +57,8 @@ describe "A service consumer side of a pact", :pact => true do
|
|
|
57
57
|
"provider_state" => "something",
|
|
58
58
|
"body"=>{
|
|
59
59
|
"a"=>{
|
|
60
|
-
"
|
|
61
|
-
"
|
|
60
|
+
"EXPECTED"=>"some body",
|
|
61
|
+
"ACTUAL"=>"not matching body"
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'pact/matchers/diff_decorator'
|
|
3
|
+
require 'pact/matchers/matchers'
|
|
4
|
+
|
|
5
|
+
module Pact
|
|
6
|
+
module Matchers
|
|
7
|
+
describe DiffDecorator do
|
|
8
|
+
|
|
9
|
+
describe "to_s" do
|
|
10
|
+
subject { DiffDecorator.new(diff) }
|
|
11
|
+
|
|
12
|
+
context "when there is a mismatched value" do
|
|
13
|
+
let(:diff) { {root: {"blah" => { 1 => Difference.new("alphabet", "woozle")}}} }
|
|
14
|
+
let(:expected_output) { ""}
|
|
15
|
+
|
|
16
|
+
it "includes the expected value" do
|
|
17
|
+
expect(subject.to_s).to match(/Expected:.*"alphabet"/m)
|
|
18
|
+
end
|
|
19
|
+
it "includes the actual value" do
|
|
20
|
+
expect(subject.to_s).to match(/Actual:.*"woozle"/m)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "includes the path" do
|
|
24
|
+
expect(subject.to_s).to include('[:root]["blah"][1]')
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "when there is a missing key" do
|
|
29
|
+
let(:expected_hash) { {"abc" => {"def" => [1,2]}}}
|
|
30
|
+
let(:diff) { {root: {"blah" => { 1 => Difference.new(expected_hash, Pact::KeyNotFound.new )}}} }
|
|
31
|
+
let(:expected_output) { ""}
|
|
32
|
+
|
|
33
|
+
it "includes the expected value" do
|
|
34
|
+
expect(subject.to_s).to match(/Missing key with value\:.*\{/m)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "includes the path" do
|
|
38
|
+
expect(subject.to_s).to include('[:root]["blah"][1]')
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context "when there is a missing index" do
|
|
43
|
+
let(:diff) { [NoDiffIndicator.new, Difference.new(1, IndexNotFound.new )]}
|
|
44
|
+
it "includes the expected value" do
|
|
45
|
+
expect(subject.to_s).to match(/Missing.*1/m)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "includes the path" do
|
|
49
|
+
expect(subject.to_s).to include('[1]')
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "when there is an unexpected index" do
|
|
54
|
+
let(:diff) { [NoDiffIndicator.new, Difference.new(UnexpectedIndex.new, 2), Difference.new(UnexpectedIndex.new, "b")]}
|
|
55
|
+
it "includes the unexpected value" do
|
|
56
|
+
expect(subject.to_s).to include("Array contained unexpected item:")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "includes the path" do
|
|
60
|
+
expect(subject.to_s).to include('[1]')
|
|
61
|
+
expect(subject.to_s).to include('[2]')
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "when there is an unexpected key" do
|
|
66
|
+
let(:diff) { {"blah" => Difference.new(UnexpectedKey.new, "b")}}
|
|
67
|
+
it "includes the unexpected key" do
|
|
68
|
+
expect(subject.to_s).to include("Hash contained unexpected key with value:")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "includes the path" do
|
|
72
|
+
expect(subject.to_s).to include('["blah"]')
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -1,424 +1,429 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'pact/matchers'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
include Pact::Matchers
|
|
4
|
+
module Pact::Matchers
|
|
6
5
|
|
|
7
|
-
describe
|
|
6
|
+
describe Pact::Matchers do
|
|
7
|
+
include Pact::Matchers
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
let(:expected) { Pact::SomethingLike.new( { a: 1 } ) }
|
|
11
|
-
let(:actual) { { a: 2} }
|
|
9
|
+
describe 'matching with something like' do
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
11
|
+
context 'when the actual is something like the expected' do
|
|
12
|
+
let(:expected) { Pact::SomethingLike.new( { a: 1 } ) }
|
|
13
|
+
let(:actual) { { a: 2} }
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
it 'returns an empty diff' do
|
|
16
|
+
expect(diff(expected, actual)).to eq({})
|
|
17
|
+
end
|
|
20
18
|
|
|
21
|
-
describe 'option {allow_unexpected_keys: false}' do
|
|
22
|
-
context "when an unexpected key is found" do
|
|
23
|
-
let(:expected) { {:a => 1} }
|
|
24
|
-
let(:actual) { {:a => 1, :b => 2} }
|
|
25
|
-
let(:difference) { {:b => {:expected => Pact::UnexpectedKey.new, :actual => 2 }} }
|
|
26
|
-
it "returns it in the diff" do
|
|
27
|
-
expect(diff(expected, actual, allow_unexpected_keys: false)).to eq difference
|
|
28
19
|
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
20
|
|
|
32
|
-
describe "expecting key to be present with nil value and not finding key" do
|
|
33
|
-
let(:expected) { {a: nil} }
|
|
34
|
-
let(:actual) { {} }
|
|
35
|
-
let(:difference) { {a: {expected: nil, actual: Pact::KeyNotFound.new }} }
|
|
36
|
-
it "returns the key in the diff" do
|
|
37
|
-
expect(diff(expected, actual)).to eq difference
|
|
38
21
|
end
|
|
39
|
-
end
|
|
40
22
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
23
|
+
describe 'option {allow_unexpected_keys: false}' do
|
|
24
|
+
context "when an unexpected key is found" do
|
|
25
|
+
let(:expected) { {:a => 1} }
|
|
26
|
+
let(:actual) { {:a => 1, :b => 2} }
|
|
27
|
+
let(:difference) { {:b => Difference.new(Pact::UnexpectedKey.new, 2 )} }
|
|
28
|
+
it "returns it in the diff" do
|
|
29
|
+
expect(diff(expected, actual, allow_unexpected_keys: false)).to eq difference
|
|
30
|
+
end
|
|
31
|
+
end
|
|
47
32
|
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
describe 'structure_diff' do
|
|
51
|
-
let(:expected) {
|
|
52
|
-
{a: 'a string', b: 1, c: nil, d: [{e: 'thing'}], f: {g: 10}, h: false}
|
|
53
|
-
}
|
|
54
33
|
|
|
55
|
-
|
|
56
|
-
let(:
|
|
57
|
-
let(:
|
|
58
|
-
|
|
59
|
-
|
|
34
|
+
describe "expecting key to be present with nil value and not finding key" do
|
|
35
|
+
let(:expected) { {a: nil} }
|
|
36
|
+
let(:actual) { {} }
|
|
37
|
+
let(:difference) { {a: Difference.new(nil, Pact::KeyNotFound.new )} }
|
|
38
|
+
it "returns the key in the diff" do
|
|
39
|
+
expect(diff(expected, actual)).to eq difference
|
|
60
40
|
end
|
|
61
41
|
end
|
|
62
42
|
|
|
63
|
-
|
|
64
|
-
let(:
|
|
65
|
-
let(:
|
|
66
|
-
let(:difference) { {:
|
|
67
|
-
it "returns the
|
|
68
|
-
expect(
|
|
43
|
+
describe "expecting a string matching a regexp and not finding key" do
|
|
44
|
+
let(:expected) { {a: /b/} }
|
|
45
|
+
let(:actual) { {} }
|
|
46
|
+
let(:difference) { {:a=> Difference.new(/b/, Pact::KeyNotFound.new) } }
|
|
47
|
+
it "returns the diff" do
|
|
48
|
+
expect(diff(expected, actual)).to eq difference
|
|
69
49
|
end
|
|
70
50
|
end
|
|
71
51
|
|
|
72
|
-
|
|
73
|
-
let(:expected) {
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
describe 'structure_diff' do
|
|
53
|
+
let(:expected) {
|
|
54
|
+
{a: 'a string', b: 1, c: nil, d: [{e: 'thing'}], f: {g: 10}, h: false}
|
|
55
|
+
}
|
|
76
56
|
|
|
77
|
-
context "
|
|
78
|
-
let(:actual) { {a: '
|
|
79
|
-
|
|
57
|
+
context "when the classes match" do
|
|
58
|
+
let(:actual) { {a: 'another string', b: 2, c: nil, d: [{e: 'something'}], f: {g: 100}, h: true} }
|
|
59
|
+
let(:difference) { {} }
|
|
60
|
+
it "returns an empty hash" do
|
|
80
61
|
expect(structure_diff(expected, actual)).to eq difference
|
|
81
62
|
end
|
|
82
63
|
end
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
let(:
|
|
86
|
-
|
|
64
|
+
|
|
65
|
+
context "when a key is not found" do
|
|
66
|
+
let(:actual) { {a: 'blah'} }
|
|
67
|
+
let(:expected) { {b: 'blah'} }
|
|
68
|
+
let(:difference) { {:b=>Difference.new({:class=>String, :eg=>"blah"}, Pact::KeyNotFound.new)} }
|
|
69
|
+
it "returns the difference" do
|
|
87
70
|
expect(structure_diff(expected, actual)).to eq difference
|
|
88
71
|
end
|
|
89
72
|
end
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
let(:
|
|
93
|
-
|
|
94
|
-
|
|
73
|
+
|
|
74
|
+
context "when a number is expected" do
|
|
75
|
+
let(:expected) { {a: 1} }
|
|
76
|
+
#let(:difference) { {a: {expected: 'Fixnum (eg. 1)', actual: 'String ("a string")'}} }
|
|
77
|
+
let(:difference) { {a: Difference.new({:class => Fixnum, eg: 1 } , {:class => String, :value => 'a string'})} }
|
|
78
|
+
|
|
79
|
+
context "and a string is found" do
|
|
80
|
+
let(:actual) { {a: 'a string'}}
|
|
81
|
+
it "returns the diff" do
|
|
82
|
+
expect(structure_diff(expected, actual)).to eq difference
|
|
83
|
+
end
|
|
95
84
|
end
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
context "and nil is found" do
|
|
86
|
+
let(:actual) { {a: nil}}
|
|
87
|
+
let(:difference ) { {a: Difference.new({:class => Fixnum, eg: 1}, nil) } }
|
|
88
|
+
it "returns the diff" do
|
|
89
|
+
expect(structure_diff(expected, actual)).to eq difference
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
context "and a hash is found" do
|
|
93
|
+
let(:actual) { {a: {b: 1}} }
|
|
94
|
+
let(:difference) { {:a=>Difference.new({:class=>Fixnum, :eg=>1}, {:class=>Hash, :value=>{:b=>1}}) } }
|
|
95
|
+
it "returns the diff" do
|
|
96
|
+
expect(structure_diff(expected, actual)).to eq difference
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
context "and an array is found" do
|
|
100
|
+
let(:actual) { {a: [1] } }
|
|
101
|
+
let(:difference) { {:a=>Difference.new({:class=>Fixnum, :eg=>1}, {:class=>Array, :value=>[1]} ) } }
|
|
102
|
+
it "returns the diff" do
|
|
103
|
+
expect(structure_diff(expected, actual)).to eq difference
|
|
104
|
+
end
|
|
102
105
|
end
|
|
103
106
|
end
|
|
104
|
-
end
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
context "when an array is expected" do
|
|
109
|
+
let(:expected) { [{name: 'Fred'}, {name: 'Mary'}] }
|
|
110
|
+
context "when an item with differing class values is found" do
|
|
111
|
+
let(:actual) { [{name: 'Fred'}, {name: 1}] }
|
|
112
|
+
let(:difference) { [
|
|
113
|
+
Pact::Matchers::NO_DIFF_INDICATOR,
|
|
114
|
+
{:name =>
|
|
115
|
+
Difference.new( { :class=>String, :eg=>"Mary" },
|
|
116
|
+
{ :class=>Fixnum, :value=>1} )
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
it "returns the diff" do
|
|
121
|
+
expect(structure_diff(expected, actual)).to eq difference
|
|
122
|
+
end
|
|
120
123
|
end
|
|
121
124
|
end
|
|
122
|
-
end
|
|
123
125
|
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
context "when nil is expected" do
|
|
128
|
+
let(:expected) { {a: nil} }
|
|
129
|
+
context "and a string is found" do
|
|
130
|
+
let(:actual) { {a: 'a string'} }
|
|
131
|
+
let(:difference) { {:a=>Difference.new(nil, {:class=>String, :value=>"a string"}) } }
|
|
132
|
+
it "returns the diff" do
|
|
133
|
+
expect(structure_diff(expected, actual)).to eq difference
|
|
134
|
+
end
|
|
132
135
|
end
|
|
133
136
|
end
|
|
134
|
-
end
|
|
135
137
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
context "when a term is expected" do
|
|
139
|
+
let(:expected) { {a: Pact::Term.new(:matcher => /p/, :generate => 'apple')} }
|
|
140
|
+
context "and a non matching string is found" do
|
|
141
|
+
let(:actual) { {a: 'banana'} }
|
|
142
|
+
let(:difference) { {:a=>Pact::Matchers::Difference.new(/p/,"banana")} }
|
|
143
|
+
it "returns the diff" do
|
|
144
|
+
expect(structure_diff(expected, actual)).to eq difference
|
|
145
|
+
end
|
|
143
146
|
end
|
|
144
147
|
end
|
|
145
148
|
end
|
|
146
|
-
end
|
|
147
149
|
|
|
148
|
-
|
|
150
|
+
describe 'diffing' do
|
|
149
151
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
context "when expected is longer than the actual" do
|
|
153
|
+
subject { [1,2,3] }
|
|
154
|
+
let(:actual) { [1,2]}
|
|
155
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(3, Pact::IndexNotFound.new)] }
|
|
156
|
+
it 'returns the diff' do
|
|
157
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
158
|
+
end
|
|
156
159
|
end
|
|
157
|
-
end
|
|
158
160
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
context "when actual array is longer than the expected" do
|
|
162
|
+
subject { [1] }
|
|
163
|
+
let(:actual) { [1,2]}
|
|
164
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(Pact::UnexpectedIndex.new, 2)] }
|
|
165
|
+
it 'returns the diff' do
|
|
166
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
167
|
+
end
|
|
165
168
|
end
|
|
166
|
-
end
|
|
167
169
|
|
|
168
|
-
|
|
170
|
+
context 'where an expected value is a non-empty string' do
|
|
169
171
|
|
|
170
|
-
|
|
172
|
+
subject { {:a => 'a', :b => 'b'} }
|
|
171
173
|
|
|
172
|
-
|
|
174
|
+
context 'and the actual value is an empty string' do
|
|
173
175
|
|
|
174
|
-
|
|
176
|
+
let(:actual) { {:a => 'a', :b => ''} }
|
|
177
|
+
|
|
178
|
+
it 'includes this in the diff' do
|
|
179
|
+
expect(diff(subject, actual)).to eq({:b => Difference.new('b', '')})
|
|
180
|
+
end
|
|
175
181
|
|
|
176
|
-
it 'includes this in the diff' do
|
|
177
|
-
expect(diff(subject, actual)).to eql({:b => {:expected => 'b', :actual => ''}})
|
|
178
182
|
end
|
|
179
183
|
|
|
180
184
|
end
|
|
181
185
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
expect(diff(subject, actual)).to eql(difference)
|
|
186
|
+
context "when the expected value is a hash" do
|
|
187
|
+
subject { {a: 'b'} }
|
|
188
|
+
context "when the actual value is an array" do
|
|
189
|
+
let(:actual) { [1] }
|
|
190
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
191
|
+
it "should return the diff" do
|
|
192
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
193
|
+
end
|
|
191
194
|
end
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
context "when the actual value is an hash" do
|
|
196
|
+
let(:actual) { {b: 'c'} }
|
|
197
|
+
let(:difference) { { a: Difference.new("b",Pact::KeyNotFound.new)} }
|
|
198
|
+
it "should return the diff" do
|
|
199
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
200
|
+
end
|
|
198
201
|
end
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
202
|
+
context "when the actual value is an number" do
|
|
203
|
+
let(:actual) { 1 }
|
|
204
|
+
let(:difference) { Difference.new({a: "b"}, 1) }
|
|
205
|
+
it "should return the diff" do
|
|
206
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
207
|
+
end
|
|
205
208
|
end
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
context "when the actual value is a string" do
|
|
210
|
+
let(:actual) { "Thing" }
|
|
211
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
212
|
+
it "should return the diff" do
|
|
213
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
214
|
+
end
|
|
212
215
|
end
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
context "when the actual value is the same" do
|
|
217
|
+
let (:actual) { {a: 'b'} }
|
|
218
|
+
it "should return an empty hash" do
|
|
219
|
+
expect(diff(subject, actual)).to eq({})
|
|
220
|
+
end
|
|
218
221
|
end
|
|
219
222
|
end
|
|
220
|
-
end
|
|
221
223
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
224
|
+
context "when the expected value is an array" do
|
|
225
|
+
subject { [1] }
|
|
226
|
+
context "when the actual value is an array" do
|
|
227
|
+
let(:actual) { [2] }
|
|
228
|
+
let(:difference) { [Difference.new(1, 2)] }
|
|
229
|
+
it "should return the diff" do
|
|
230
|
+
expect(diff(subject, actual)).to eq difference
|
|
231
|
+
end
|
|
229
232
|
end
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
context "when the actual value is an hash" do
|
|
234
|
+
let(:actual) { {b: 'c'} }
|
|
235
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
236
|
+
it "should return the diff" do
|
|
237
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
238
|
+
end
|
|
236
239
|
end
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
context "when the actual value is an number" do
|
|
241
|
+
let(:actual) { 1 }
|
|
242
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
243
|
+
it "should return the diff" do
|
|
244
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
245
|
+
end
|
|
243
246
|
end
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
247
|
+
context "when the actual value is a string" do
|
|
248
|
+
let(:actual) { "Thing" }
|
|
249
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
250
|
+
it "should return the diff" do
|
|
251
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
252
|
+
end
|
|
250
253
|
end
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
context "when the actual value is the same" do
|
|
255
|
+
let (:actual) { [1] }
|
|
256
|
+
it "should return an empty hash" do
|
|
257
|
+
expect(diff(subject, actual)).to eql({})
|
|
258
|
+
end
|
|
256
259
|
end
|
|
257
260
|
end
|
|
258
|
-
end
|
|
259
261
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
262
|
+
context "when the expected value is a string" do
|
|
263
|
+
subject { "Thing"}
|
|
264
|
+
context "when the actual value is an array" do
|
|
265
|
+
let(:actual) { [2] }
|
|
266
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
267
|
+
it "should return the diff" do
|
|
268
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
269
|
+
end
|
|
267
270
|
end
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
271
|
+
context "when the actual value is an hash" do
|
|
272
|
+
let(:actual) { {b: 'c'} }
|
|
273
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
274
|
+
it "should return the diff" do
|
|
275
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
276
|
+
end
|
|
274
277
|
end
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
278
|
+
context "when the actual value is an number" do
|
|
279
|
+
let(:actual) { 1 }
|
|
280
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
281
|
+
it "should return the diff" do
|
|
282
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
283
|
+
end
|
|
281
284
|
end
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
context "when the actual value is a string" do
|
|
286
|
+
let(:actual) { "Another Thing" }
|
|
287
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
288
|
+
it "should return the diff" do
|
|
289
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
290
|
+
end
|
|
288
291
|
end
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
context "when the actual value is the same" do
|
|
293
|
+
let (:actual) { "Thing" }
|
|
294
|
+
it "should return an empty hash" do
|
|
295
|
+
expect(diff(subject, actual)).to eq({})
|
|
296
|
+
end
|
|
294
297
|
end
|
|
295
298
|
end
|
|
296
|
-
end
|
|
297
299
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
300
|
+
context "when the expected value is a number" do
|
|
301
|
+
subject { 1 }
|
|
302
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
303
|
+
context "when the actual value is an array" do
|
|
304
|
+
let(:actual) { [2] }
|
|
305
|
+
it "should return the diff" do
|
|
306
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
307
|
+
end
|
|
305
308
|
end
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
309
|
+
context "when the actual value is an hash" do
|
|
310
|
+
let(:actual) { {b: 'c'} }
|
|
311
|
+
it "should return the diff" do
|
|
312
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
313
|
+
end
|
|
311
314
|
end
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
context "when the actual value is an number" do
|
|
316
|
+
let(:actual) { 2 }
|
|
317
|
+
it "should return the diff" do
|
|
318
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
319
|
+
end
|
|
317
320
|
end
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
321
|
+
context "when the actual value is a string" do
|
|
322
|
+
let(:actual) { "Another Thing" }
|
|
323
|
+
it "should return the diff" do
|
|
324
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
325
|
+
end
|
|
323
326
|
end
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
327
|
+
context "when the actual value is the same" do
|
|
328
|
+
let (:actual) { 1 }
|
|
329
|
+
it "should return an empty hash" do
|
|
330
|
+
expect(diff(subject, actual)).to eq({})
|
|
331
|
+
end
|
|
329
332
|
end
|
|
330
333
|
end
|
|
331
|
-
end
|
|
332
334
|
|
|
333
|
-
|
|
335
|
+
context "when the expected value is a String matcher" do
|
|
334
336
|
|
|
335
|
-
|
|
337
|
+
end
|
|
336
338
|
|
|
337
|
-
|
|
339
|
+
context "when the expected value is a Number matcher" do
|
|
338
340
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
+
end
|
|
342
|
+
context "when the expected value is an array with a matcher" do
|
|
341
343
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
+
end
|
|
345
|
+
context "when the expected value is a hash with a matcher" do
|
|
344
346
|
|
|
345
|
-
|
|
347
|
+
end
|
|
346
348
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
349
|
+
context "when an expected value is nil but not nil is found" do
|
|
350
|
+
subject { {a: nil} }
|
|
351
|
+
let(:actual) { {a: 'blah'} }
|
|
352
|
+
let(:difference) { {:a=>Difference.new(nil, "blah")} }
|
|
353
|
+
it "should return the diff" do
|
|
354
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
355
|
+
end
|
|
353
356
|
end
|
|
354
|
-
end
|
|
355
357
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
358
|
+
context "a deep mismatch" do
|
|
359
|
+
subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/, generate: 'apple')}}, f: 1, g: {h: 99}} }
|
|
360
|
+
let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} }
|
|
361
|
+
let(:difference) { {:a=>{:d=>{:e=> Difference.new(/a/, "food")}},
|
|
362
|
+
:f=> Difference.new(1, "thing"),
|
|
363
|
+
:g=>Difference.new({:h=>99}, Pact::KeyNotFound.new)} }
|
|
360
364
|
|
|
361
|
-
|
|
362
|
-
|
|
365
|
+
it 'should return the diff' do
|
|
366
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
367
|
+
end
|
|
363
368
|
end
|
|
364
|
-
end
|
|
365
369
|
|
|
366
370
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
371
|
+
context "where a Pact::Term is found that matches the actual value" do
|
|
372
|
+
subject { {:a => Pact::Term.new(:matcher => /a/, :generate => 'apple')} }
|
|
373
|
+
let(:actual) { {:a => "apple" } }
|
|
370
374
|
|
|
371
|
-
|
|
372
|
-
|
|
375
|
+
it 'does not include this in the diff' do
|
|
376
|
+
expect(diff(subject, actual)).to eq({})
|
|
377
|
+
end
|
|
373
378
|
end
|
|
374
|
-
end
|
|
375
379
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
380
|
+
context "where an array is expected at a key inside a hash, but a hash is found" do
|
|
381
|
+
subject { {:a => [1,2,3]} }
|
|
382
|
+
let(:actual) { {:a => {:b => 1} } }
|
|
379
383
|
|
|
380
|
-
|
|
381
|
-
|
|
384
|
+
it 'includes this in the diff' do
|
|
385
|
+
expect(diff(subject, actual)).to eq({:a => Difference.new([1,2,3], {:b => 1})})
|
|
386
|
+
end
|
|
382
387
|
end
|
|
383
|
-
end
|
|
384
388
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
389
|
+
context "where an array is expected, but a hash is found" do
|
|
390
|
+
subject { {:a => :b} }
|
|
391
|
+
let(:actual) { [4,5,6] }
|
|
388
392
|
|
|
389
|
-
|
|
390
|
-
|
|
393
|
+
it 'includes this in the diff' do
|
|
394
|
+
expect(diff(subject, actual)).to eq(Difference.new({:a => :b}, [4,5,6] ))
|
|
395
|
+
end
|
|
391
396
|
end
|
|
392
|
-
end
|
|
393
397
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
398
|
+
context "where a hash is expected, but array is found" do
|
|
399
|
+
subject { [4,5,6] }
|
|
400
|
+
let(:actual) { {:a => :b} }
|
|
397
401
|
|
|
398
|
-
|
|
399
|
-
|
|
402
|
+
it 'includes this in the diff' do
|
|
403
|
+
expect(diff(subject, actual)).to eq(Difference.new([4,5,6],{:a => :b}))
|
|
404
|
+
end
|
|
400
405
|
end
|
|
401
|
-
end
|
|
402
406
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
+
context "when two different arrays are found" do
|
|
408
|
+
subject { [4,5,6] }
|
|
409
|
+
let(:actual) { [4,6,7] }
|
|
410
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(5, 6), Difference.new(6, 7)] }
|
|
407
411
|
|
|
408
|
-
|
|
409
|
-
|
|
412
|
+
it 'includes this in the diff' do
|
|
413
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
414
|
+
end
|
|
410
415
|
end
|
|
411
|
-
end
|
|
412
416
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
417
|
+
context "when an array that matches the Pact::Term is found" do
|
|
418
|
+
subject { [Pact::Term.new(:matcher => /4/, :generate => '4'),"5","6"] }
|
|
419
|
+
let(:actual) { ["4","5","6"] }
|
|
416
420
|
|
|
417
|
-
|
|
418
|
-
|
|
421
|
+
it 'includes this in the diff' do
|
|
422
|
+
expect(diff(subject, actual)).to eq({})
|
|
423
|
+
end
|
|
419
424
|
end
|
|
425
|
+
|
|
420
426
|
end
|
|
421
427
|
|
|
422
428
|
end
|
|
423
|
-
|
|
424
429
|
end
|