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.
@@ -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 %>
@@ -1,3 +1,3 @@
1
1
  module Pact
2
- VERSION = "1.0.26"
2
+ VERSION = "1.0.27"
3
3
  end
@@ -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
- "expected"=>"some body",
61
- "actual"=>"not matching body"
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
- describe Pact::Matchers do
5
- include Pact::Matchers
4
+ module Pact::Matchers
6
5
 
7
- describe 'matching with something like' do
6
+ describe Pact::Matchers do
7
+ include Pact::Matchers
8
8
 
9
- context 'when the actual is something like the expected' do
10
- let(:expected) { Pact::SomethingLike.new( { a: 1 } ) }
11
- let(:actual) { { a: 2} }
9
+ describe 'matching with something like' do
12
10
 
13
- it 'returns an empty diff' do
14
- expect(diff(expected, actual)).to eq({})
15
- end
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
- end
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
- describe "expecting a string matching a regexp and not finding key" do
42
- let(:expected) { {a: /b/} }
43
- let(:actual) { {} }
44
- let(:difference) { {:a=>{:expected=>/b/, :actual=> Pact::KeyNotFound.new }} }
45
- it "returns the diff" do
46
- expect(diff(expected, actual)).to eq difference
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
- context "when the classes match" do
56
- let(:actual) { {a: 'another string', b: 2, c: nil, d: [{e: 'something'}], f: {g: 100}, h: true} }
57
- let(:difference) { {} }
58
- it "returns an empty hash" do
59
- expect(structure_diff(expected, actual)).to eq difference
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
- context "when a key is not found" do
64
- let(:actual) { {a: 'blah'} }
65
- let(:expected) { {b: 'blah'} }
66
- let(:difference) { {:b=>{:expected=>{:class=>String, :eg=>"blah"}, :actual=>Pact::KeyNotFound.new}} }
67
- it "returns the difference" do
68
- expect(structure_diff(expected, actual)).to eq difference
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
- context "when a number is expected" do
73
- let(:expected) { {a: 1} }
74
- #let(:difference) { {a: {expected: 'Fixnum (eg. 1)', actual: 'String ("a string")'}} }
75
- let(:difference) { {a: {expected: {:class => Fixnum, eg: 1 } , actual: {:class => String, :value => 'a string'}}} }
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 "and a string is found" do
78
- let(:actual) { {a: 'a string'}}
79
- it "returns the diff" do
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
- context "and nil is found" do
84
- let(:actual) { {a: nil}}
85
- let(:difference ) { {a: {:expected => {:class => Fixnum, eg: 1}, :actual => nil} } }
86
- it "returns the diff" do
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
- context "and a hash is found" do
91
- let(:actual) { {a: {b: 1}} }
92
- let(:difference) { {:a=>{:expected=>{:class=>Fixnum, :eg=>1}, :actual=>{:class=>Hash, :value=>{:b=>1}}}} }
93
- it "returns the diff" do
94
- expect(structure_diff(expected, actual)).to eq difference
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
- end
97
- context "and an array is found" do
98
- let(:actual) { {a: [1] } }
99
- let(:difference) { {:a=>{:expected=>{:class=>Fixnum, :eg=>1}, :actual=>{:class=>Array, :value=>[1]}}} }
100
- it "returns the diff" do
101
- expect(structure_diff(expected, actual)).to eq difference
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
- context "when an array is expected" do
107
- let(:expected) { [{name: 'Fred'}, {name: 'Mary'}] }
108
- context "when an item with differing class values is found" do
109
- let(:actual) { [{name: 'Fred'}, {name: 1}] }
110
- let(:difference) { [
111
- Pact::Matchers::NO_DIFF_INDICATOR,
112
- {:name => {
113
- :expected=> { :class=>String, :eg=>"Mary" },
114
- :actual=> { :class=>Fixnum, :value=>1} }
115
- }
116
- ]
117
- }
118
- it "returns the diff" do
119
- expect(structure_diff(expected, actual)).to eq difference
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
- context "when nil is expected" do
126
- let(:expected) { {a: nil} }
127
- context "and a string is found" do
128
- let(:actual) { {a: 'a string'} }
129
- let(:difference) { {:a=>{:expected=>nil, :actual=>{:class=>String, :value=>"a string"}}} }
130
- it "returns the diff" do
131
- expect(structure_diff(expected, actual)).to eq difference
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
- context "when a term is expected" do
137
- let(:expected) { {a: Pact::Term.new(:matcher => /p/, :generate => 'apple')} }
138
- context "and a non matching string is found" do
139
- let(:actual) { {a: 'banana'} }
140
- let(:difference) { {:a=>{:expected=>/p/, :actual=>"banana"}} }
141
- it "returns the diff" do
142
- expect(structure_diff(expected, actual)).to eq difference
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
- describe 'diffing' do
150
+ describe 'diffing' do
149
151
 
150
- context "when expected is longer than the actual" do
151
- subject { [1,2,3] }
152
- let(:actual) { [1,2]}
153
- let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Pact::Matchers::NO_DIFF_INDICATOR, {expected: 3, actual: Pact::IndexNotFound.new}] }
154
- it 'returns the diff' do
155
- expect(diff(subject, actual)).to eq(difference)
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
- context "when actual array is longer than the expected" do
160
- subject { [1] }
161
- let(:actual) { [1,2]}
162
- let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, {expected: Pact::UnexpectedIndex.new , actual: 2}] }
163
- it 'returns the diff' do
164
- expect(diff(subject, actual)).to eq(difference)
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
- context 'where an expected value is a non-empty string' do
170
+ context 'where an expected value is a non-empty string' do
169
171
 
170
- subject { {:a => 'a', :b => 'b'} }
172
+ subject { {:a => 'a', :b => 'b'} }
171
173
 
172
- context 'and the actual value is an empty string' do
174
+ context 'and the actual value is an empty string' do
173
175
 
174
- let(:actual) { {:a => 'a', :b => ''} }
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
- end
183
-
184
- context "when the expected value is a hash" do
185
- subject { {a: 'b'} }
186
- context "when the actual value is an array" do
187
- let(:actual) { [1] }
188
- let(:difference) { {expected: subject, actual: actual} }
189
- it "should return the diff" do
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
- end
193
- context "when the actual value is an hash" do
194
- let(:actual) { {b: 'c'} }
195
- let(:difference) { { a: {expected:"b", actual: Pact::KeyNotFound.new}} }
196
- it "should return the diff" do
197
- expect(diff(subject, actual)).to eql(difference)
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
- end
200
- context "when the actual value is an number" do
201
- let(:actual) { 1 }
202
- let(:difference) { {expected: {a: "b"}, actual: 1} }
203
- it "should return the diff" do
204
- expect(diff(subject, actual)).to eql(difference)
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
- end
207
- context "when the actual value is a string" do
208
- let(:actual) { "Thing" }
209
- let(:difference) { {expected: subject, actual: actual} }
210
- it "should return the diff" do
211
- expect(diff(subject, actual)).to eql(difference)
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
- end
214
- context "when the actual value is the same" do
215
- let (:actual) { {a: 'b'} }
216
- it "should return an empty hash" do
217
- expect(diff(subject, actual)).to eql({})
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
- context "when the expected value is an array" do
223
- subject { [1] }
224
- context "when the actual value is an array" do
225
- let(:actual) { [2] }
226
- let(:difference) { {expected: subject, actual: actual} }
227
- it "should return the diff" do
228
- expect(diff(subject, actual)).to eql([{expected: 1, actual: 2}])
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
- end
231
- context "when the actual value is an hash" do
232
- let(:actual) { {b: 'c'} }
233
- let(:difference) { {expected: subject, actual: actual} }
234
- it "should return the diff" do
235
- expect(diff(subject, actual)).to eql(difference)
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
- end
238
- context "when the actual value is an number" do
239
- let(:actual) { 1 }
240
- let(:difference) { {expected: subject, actual: actual} }
241
- it "should return the diff" do
242
- expect(diff(subject, actual)).to eql(difference)
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
- end
245
- context "when the actual value is a string" do
246
- let(:actual) { "Thing" }
247
- let(:difference) { {expected: subject, actual: actual} }
248
- it "should return the diff" do
249
- expect(diff(subject, actual)).to eql(difference)
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
- end
252
- context "when the actual value is the same" do
253
- let (:actual) { [1] }
254
- it "should return an empty hash" do
255
- expect(diff(subject, actual)).to eql({})
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
- context "when the expected value is a string" do
261
- subject { "Thing"}
262
- context "when the actual value is an array" do
263
- let(:actual) { [2] }
264
- let(:difference) { {expected: subject, actual: actual} }
265
- it "should return the diff" do
266
- expect(diff(subject, actual)).to eql(difference)
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
- end
269
- context "when the actual value is an hash" do
270
- let(:actual) { {b: 'c'} }
271
- let(:difference) { {expected: subject, actual: actual} }
272
- it "should return the diff" do
273
- expect(diff(subject, actual)).to eql(difference)
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
- end
276
- context "when the actual value is an number" do
277
- let(:actual) { 1 }
278
- let(:difference) { {expected: subject, actual: actual} }
279
- it "should return the diff" do
280
- expect(diff(subject, actual)).to eql(difference)
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
- end
283
- context "when the actual value is a string" do
284
- let(:actual) { "Another Thing" }
285
- let(:difference) { {expected: subject, actual: actual} }
286
- it "should return the diff" do
287
- expect(diff(subject, actual)).to eql(difference)
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
- end
290
- context "when the actual value is the same" do
291
- let (:actual) { "Thing" }
292
- it "should return an empty hash" do
293
- expect(diff(subject, actual)).to eql({})
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
- context "when the expected value is a number" do
299
- subject { 1 }
300
- let(:difference) { {expected: subject, actual: actual} }
301
- context "when the actual value is an array" do
302
- let(:actual) { [2] }
303
- it "should return the diff" do
304
- expect(diff(subject, actual)).to eql(difference)
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
- end
307
- context "when the actual value is an hash" do
308
- let(:actual) { {b: 'c'} }
309
- it "should return the diff" do
310
- expect(diff(subject, actual)).to eql(difference)
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
- end
313
- context "when the actual value is an number" do
314
- let(:actual) { 2 }
315
- it "should return the diff" do
316
- expect(diff(subject, actual)).to eql(difference)
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
- end
319
- context "when the actual value is a string" do
320
- let(:actual) { "Another Thing" }
321
- it "should return the diff" do
322
- expect(diff(subject, actual)).to eql(difference)
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
- 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({})
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
- context "when the expected value is a String matcher" do
335
+ context "when the expected value is a String matcher" do
334
336
 
335
- end
337
+ end
336
338
 
337
- context "when the expected value is a Number matcher" do
339
+ context "when the expected value is a Number matcher" do
338
340
 
339
- end
340
- context "when the expected value is an array with a matcher" do
341
+ end
342
+ context "when the expected value is an array with a matcher" do
341
343
 
342
- end
343
- context "when the expected value is a hash with a matcher" do
344
+ end
345
+ context "when the expected value is a hash with a matcher" do
344
346
 
345
- end
347
+ end
346
348
 
347
- context "when an expected value is nil but not nil is found" do
348
- subject { {a: nil} }
349
- let(:actual) { {a: 'blah'} }
350
- let(:difference) { {:a=>{:expected=>nil, :actual=>"blah"}} }
351
- it "should return the diff" do
352
- expect(diff(subject, actual)).to eql(difference)
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
- context "a deep mismatch" do
357
- subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/, generate: 'apple')}}, f: 1, g: {h: 99}} }
358
- let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} }
359
- let(:difference) { {:a=>{:d=>{:e=>{:expected=>/a/, :actual=>"food"}}}, :f=>{:expected=>1, :actual=>"thing"}, :g=>{:expected=>{:h=>99}, :actual=> Pact::KeyNotFound.new}} }
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
- it 'should return the diff' do
362
- expect(diff(subject, actual)).to eq(difference)
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
- context "where a Pact::Term is found that matches the actual value" do
368
- subject { {:a => Pact::Term.new(:matcher => /a/, :generate => 'apple')} }
369
- let(:actual) { {:a => "apple" } }
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
- it 'does not include this in the diff' do
372
- expect(diff(subject, actual)).to eq({})
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
- context "where an array is expected at a key inside a hash, but a hash is found" do
377
- subject { {:a => [1,2,3]} }
378
- let(:actual) { {:a => {:b => 1} } }
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
- it 'includes this in the diff' do
381
- expect(diff(subject, actual)).to eql({:a => {:expected => [1,2,3], :actual => {:b => 1}}})
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
- context "where an array is expected, but a hash is found" do
386
- subject { {:a => :b} }
387
- let(:actual) { [4,5,6] }
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
- it 'includes this in the diff' do
390
- expect(diff(subject, actual)).to eq({:expected => {:a => :b}, :actual => [4,5,6] })
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
- context "where a hash is expected, but array is found" do
395
- subject { [4,5,6] }
396
- let(:actual) { {:a => :b} }
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
- it 'includes this in the diff' do
399
- expect(diff(subject, actual)).to eq({:expected => [4,5,6], :actual => {:a => :b} })
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
- context "when two different arrays are found" do
404
- subject { [4,5,6] }
405
- let(:actual) { [4,6,7] }
406
- let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, {:expected=>5, :actual=>6}, {:expected=>6, :actual=>7}] }
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
- it 'includes this in the diff' do
409
- expect(diff(subject, actual)).to eq(difference)
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
- context "when an array that matches the Pact::Term is found" do
414
- subject { [Pact::Term.new(:matcher => /4/, :generate => '4'),"5","6"] }
415
- let(:actual) { ["4","5","6"] }
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
- it 'includes this in the diff' do
418
- expect(diff(subject, actual)).to eq({})
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