pact 1.3.3 → 1.4.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/CHANGELOG.md +16 -1
  2. data/Gemfile +5 -0
  3. data/Gemfile.lock +34 -13
  4. data/README.md +3 -2
  5. data/example/animal-service/lib/animal_service/api.rb +1 -0
  6. data/example/zoo-app/lib/zoo_app/animal_service_client.rb +0 -9
  7. data/example/zoo-app/lib/zoo_app/models/alligator.rb +2 -0
  8. data/lib/pact.rb +6 -5
  9. data/lib/pact/cli.rb +0 -26
  10. data/lib/pact/consumer/configuration.rb +0 -1
  11. data/lib/pact/consumer/configuration/configuration_extensions.rb +51 -0
  12. data/lib/pact/consumer/consumer_contract_builder.rb +1 -2
  13. data/lib/pact/consumer/interaction_builder.rb +2 -4
  14. data/lib/pact/doc/interaction_view_model.rb +9 -6
  15. data/lib/pact/doc/sort_interactions.rb +1 -1
  16. data/lib/pact/provider/rspec.rb +11 -9
  17. data/lib/pact/version.rb +1 -1
  18. data/pact.gemspec +5 -0
  19. data/spec/lib/pact/consumer/interaction_builder_spec.rb +4 -8
  20. data/spec/support/case-insensitive-response-header-matching.json +21 -0
  21. data/spec/support/case-insensitive-response-header-matching.rb +15 -0
  22. data/tasks/pact-test.rake +5 -0
  23. metadata +42 -122
  24. data/lib/pact/configuration.rb +0 -195
  25. data/lib/pact/consumer/app_manager.rb +0 -158
  26. data/lib/pact/consumer/interactions_filter.rb +0 -48
  27. data/lib/pact/consumer/mock_service.rb +0 -2
  28. data/lib/pact/consumer/mock_service/app.rb +0 -82
  29. data/lib/pact/consumer/mock_service/interaction_delete.rb +0 -33
  30. data/lib/pact/consumer/mock_service/interaction_list.rb +0 -76
  31. data/lib/pact/consumer/mock_service/interaction_mismatch.rb +0 -73
  32. data/lib/pact/consumer/mock_service/interaction_post.rb +0 -31
  33. data/lib/pact/consumer/mock_service/interaction_replay.rb +0 -139
  34. data/lib/pact/consumer/mock_service/log_get.rb +0 -28
  35. data/lib/pact/consumer/mock_service/missing_interactions_get.rb +0 -30
  36. data/lib/pact/consumer/mock_service/mock_service_administration_endpoint.rb +0 -31
  37. data/lib/pact/consumer/mock_service/pact_post.rb +0 -33
  38. data/lib/pact/consumer/mock_service/rack_request_helper.rb +0 -51
  39. data/lib/pact/consumer/mock_service/verification_get.rb +0 -68
  40. data/lib/pact/consumer/mock_service_client.rb +0 -65
  41. data/lib/pact/consumer/mock_service_interaction_expectation.rb +0 -37
  42. data/lib/pact/consumer/request.rb +0 -27
  43. data/lib/pact/consumer/server.rb +0 -90
  44. data/lib/pact/consumer_contract.rb +0 -1
  45. data/lib/pact/consumer_contract/consumer_contract.rb +0 -115
  46. data/lib/pact/consumer_contract/consumer_contract_writer.rb +0 -84
  47. data/lib/pact/consumer_contract/file_name.rb +0 -19
  48. data/lib/pact/consumer_contract/headers.rb +0 -51
  49. data/lib/pact/consumer_contract/interaction.rb +0 -67
  50. data/lib/pact/consumer_contract/pact_file.rb +0 -24
  51. data/lib/pact/consumer_contract/request.rb +0 -73
  52. data/lib/pact/consumer_contract/service_consumer.rb +0 -28
  53. data/lib/pact/consumer_contract/service_provider.rb +0 -28
  54. data/lib/pact/logging.rb +0 -14
  55. data/lib/pact/matchers.rb +0 -1
  56. data/lib/pact/matchers/actual_type.rb +0 -16
  57. data/lib/pact/matchers/base_difference.rb +0 -37
  58. data/lib/pact/matchers/differ.rb +0 -153
  59. data/lib/pact/matchers/difference.rb +0 -13
  60. data/lib/pact/matchers/difference_indicator.rb +0 -26
  61. data/lib/pact/matchers/embedded_diff_formatter.rb +0 -62
  62. data/lib/pact/matchers/expected_type.rb +0 -35
  63. data/lib/pact/matchers/index_not_found.rb +0 -15
  64. data/lib/pact/matchers/list_diff_formatter.rb +0 -101
  65. data/lib/pact/matchers/matchers.rb +0 -139
  66. data/lib/pact/matchers/no_diff_indicator.rb +0 -18
  67. data/lib/pact/matchers/regexp_difference.rb +0 -13
  68. data/lib/pact/matchers/type_difference.rb +0 -16
  69. data/lib/pact/matchers/unexpected_index.rb +0 -11
  70. data/lib/pact/matchers/unexpected_key.rb +0 -11
  71. data/lib/pact/matchers/unix_diff_formatter.rb +0 -114
  72. data/lib/pact/reification.rb +0 -28
  73. data/lib/pact/rspec.rb +0 -53
  74. data/lib/pact/shared/active_support_support.rb +0 -51
  75. data/lib/pact/shared/dsl.rb +0 -76
  76. data/lib/pact/shared/jruby_support.rb +0 -18
  77. data/lib/pact/shared/json_differ.rb +0 -15
  78. data/lib/pact/shared/key_not_found.rb +0 -15
  79. data/lib/pact/shared/null_expectation.rb +0 -31
  80. data/lib/pact/shared/request.rb +0 -80
  81. data/lib/pact/shared/text_differ.rb +0 -14
  82. data/lib/pact/something_like.rb +0 -49
  83. data/lib/pact/symbolize_keys.rb +0 -12
  84. data/lib/pact/term.rb +0 -85
  85. data/spec/lib/pact/consumer/request_spec.rb +0 -24
  86. data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
  87. data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -180
  88. data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
  89. data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -107
  90. data/spec/lib/pact/consumer_contract/request_spec.rb +0 -329
  91. data/spec/lib/pact/matchers/differ_spec.rb +0 -214
  92. data/spec/lib/pact/matchers/difference_spec.rb +0 -22
  93. data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
  94. data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
  95. data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -114
  96. data/spec/lib/pact/matchers/matchers_spec.rb +0 -500
  97. data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
  98. data/spec/lib/pact/matchers/type_difference_spec.rb +0 -34
  99. data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
  100. data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
  101. data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -216
  102. data/spec/lib/pact/reification_spec.rb +0 -67
  103. data/spec/lib/pact/shared/dsl_spec.rb +0 -86
  104. data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
  105. data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
  106. data/spec/lib/pact/shared/request_spec.rb +0 -111
  107. data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
  108. data/spec/lib/pact/something_like_spec.rb +0 -21
  109. data/spec/lib/pact/term_spec.rb +0 -89
  110. data/spec/support/dsl_spec_support.rb +0 -7
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers/difference'
3
-
4
- module Pact
5
- module Matchers
6
- describe Difference do
7
-
8
- describe "#as_json" do
9
-
10
- context "when something other than a regexp is expected" do
11
-
12
- subject { Difference.new("apple", 'pear').as_json }
13
-
14
- it "indicates that the actual was intended 'to eq'" do
15
- expect(subject).to eq({:EXPECTED => "apple", :ACTUAL => "pear"})
16
- end
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
@@ -1,90 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers/embedded_diff_formatter'
3
- require 'pact/matchers/type_difference'
4
- require 'pact/matchers/expected_type'
5
- require 'pact/matchers/actual_type'
6
-
7
- module Pact
8
- module Matchers
9
- describe EmbeddedDiffFormatter do
10
-
11
- let(:diff) do
12
- {
13
- :something => TypeDifference.new(ExpectedType.new("Fred"), ActualType.new(1))
14
- }
15
- end
16
-
17
- subject { EmbeddedDiffFormatter.call(diff, options) }
18
-
19
- let(:options) { { colour: colour }}
20
- let(:expected_coloured) { '"' + ::Term::ANSIColor.red("expected_type") + '":'}
21
- let(:actual_coloured) { '"' + ::Term::ANSIColor.green("actual_type") + '":'}
22
-
23
- describe ".call" do
24
-
25
- let(:colour) { false }
26
-
27
- context "when color_enabled is true" do
28
-
29
- let(:colour) { true }
30
-
31
- it "returns nicely formatted json" do
32
- expect(subject.split("\n").size).to eq 6
33
- end
34
-
35
- it "returns a string displaying the diff in colour" do
36
- expect(subject).to include expected_coloured
37
- expect(subject).to include actual_coloured
38
- end
39
- end
40
-
41
- context "when color_enabled is false" do
42
-
43
- let(:colour) { false }
44
-
45
- it "returns nicely formatted json" do
46
- expect(subject.split("\n").size).to eq 6
47
- end
48
-
49
- it "returns a string displaying the diff without colour" do
50
- expect(subject).to_not include expected_coloured
51
- expect(subject).to_not include actual_coloured
52
- end
53
- end
54
-
55
- context "with a Pact::Term" do
56
- let(:diff) { {thing: Difference.new(Pact::Term.new(generate: "Joe", matcher: /Jo/), "Mary")} }
57
-
58
- xit "displays the matcher from the Pact::Term" do
59
- expect(subject).to_not include("Pact::Term")
60
- expect(subject).to include("/Jo/")
61
- end
62
-
63
- end
64
-
65
- context "when no options are specified" do
66
- subject { EmbeddedDiffFormatter.call(diff) }
67
-
68
- context "when Pact.configuration.color_enabled is true" do
69
- it "returns a string displaying the diff in colour" do
70
- expect(Pact.configuration).to receive(:color_enabled).and_return(true)
71
- expect(subject).to include expected_coloured
72
- expect(subject).to include actual_coloured
73
- end
74
- end
75
-
76
- context "when Pact.configuration.color_enabled is false" do
77
- it "returns a string displaying the diff without colour" do
78
- expect(Pact.configuration).to receive(:color_enabled).and_return(false)
79
- expect(subject).to_not include expected_coloured
80
- expect(subject).to_not include actual_coloured
81
- end
82
- end
83
-
84
- end
85
- end
86
-
87
- end
88
-
89
- end
90
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers/index_not_found'
3
-
4
- module Pact
5
- describe IndexNotFound 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
-
21
- end
@@ -1,114 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/matchers/list_diff_formatter'
3
- require 'pact/matchers/matchers'
4
-
5
- module Pact
6
- module Matchers
7
- describe ListDiffFormatter do
8
-
9
- describe ".call" do
10
- subject{ ListDiffFormatter.call(diff, {}) }
11
-
12
- context "when using class based matching" do
13
- let(:diff) { {root: TypeDifference.new(ExpectedType.new("Fred"), ActualType.new(1)) } }
14
- let(:expected_output) { <<-EOS
15
- \tAt:
16
- \t\t[:root]
17
- \tExpected type:
18
- \t\tString
19
- \tActual type:
20
- \t\tFixnum
21
- EOS
22
- }
23
-
24
- it "shows the expected and actual classes" do
25
- expect(subject + "\n").to eq(expected_output)
26
- end
27
-
28
- end
29
-
30
- context "when there is an unmatched regexp" do
31
- let(:diff) { {root: RegexpDifference.new(/fr.*ed/, "mary") } }
32
- let(:expected_output) { <<-EOS
33
- \tAt:
34
- \t\t[:root]
35
- \tExpected to match:
36
- \t\t/fr.*ed/
37
- \tActual:
38
- \t\t"mary"
39
- EOS
40
- }
41
- it "shows the expected regexp" do
42
- expect(subject + "\n").to eq(expected_output)
43
- end
44
- end
45
-
46
- context "when there is a mismatched value" do
47
- let(:diff) { {root: {"blah" => { 1 => Difference.new("alphabet", "woozle")}}} }
48
- let(:expected_output) { ""}
49
-
50
- it "includes the expected value" do
51
- expect(subject).to match(/Expected:.*"alphabet"/m)
52
- end
53
- it "includes the actual value" do
54
- expect(subject).to match(/Actual:.*"woozle"/m)
55
- end
56
-
57
- it "includes the path" do
58
- expect(subject).to include('[:root]["blah"][1]')
59
- end
60
- end
61
-
62
- context "when there is a missing key" do
63
- let(:expected_hash) { {"abc" => {"def" => [1,2]}}}
64
- let(:diff) { {root: {"blah" => { 1 => Difference.new(expected_hash, Pact::KeyNotFound.new )}}} }
65
- let(:expected_output) { ""}
66
-
67
- it "includes the expected value" do
68
- expect(subject).to match(/Missing key with value\:.*\{/m)
69
- end
70
-
71
- it "includes the path" do
72
- expect(subject).to include('[:root]["blah"][1]')
73
- end
74
- end
75
-
76
- context "when there is a missing index" do
77
- let(:diff) { [NoDiffIndicator.new, Difference.new(1, IndexNotFound.new )]}
78
- it "includes the expected value" do
79
- expect(subject).to match(/Missing.*1/m)
80
- end
81
-
82
- it "includes the path" do
83
- expect(subject).to include('[1]')
84
- end
85
- end
86
-
87
- context "when there is an unexpected index" do
88
- let(:diff) { [NoDiffIndicator.new, Difference.new(UnexpectedIndex.new, 2), Difference.new(UnexpectedIndex.new, "b")]}
89
- it "includes the unexpected value" do
90
- expect(subject).to include("Array contained unexpected item:")
91
- end
92
-
93
- it "includes the path" do
94
- expect(subject).to include('[1]')
95
- expect(subject).to include('[2]')
96
- end
97
- end
98
-
99
- context "when there is an unexpected key" do
100
- let(:diff) { {"blah" => Difference.new(UnexpectedKey.new, "b")}}
101
- it "includes the unexpected key" do
102
- expect(subject).to include("Hash contained unexpected key with value:")
103
- end
104
-
105
- it "includes the path" do
106
- expect(subject).to include('["blah"]')
107
- end
108
- end
109
-
110
- end
111
-
112
- end
113
- end
114
- end
@@ -1,500 +0,0 @@
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