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,107 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/reification'
3
- require 'pact/consumer_contract/interaction'
4
-
5
- module Pact
6
- module Consumer
7
-
8
- describe Interaction do
9
-
10
- let(:request) { {method: 'get', path: 'path'} }
11
- let(:response) { {} }
12
-
13
- describe "==" do
14
- subject { InteractionFactory.create }
15
- context "when other is the same" do
16
- let(:other) { InteractionFactory.create }
17
- it "returns true" do
18
- expect(subject == other).to be true
19
- end
20
- end
21
- context "when other is not the same" do
22
- let(:other) { InteractionFactory.create(:request => {:path => '/a_different_path'}) }
23
- it "returns false" do
24
- expect(subject == other).to be false
25
- end
26
- end
27
- end
28
-
29
- describe "matches_criteria?" do
30
- subject { InteractionFactory.create(:description => 'a request for food') }
31
- context "by description" do
32
- context "when the interaction matches" do
33
- it "returns true" do
34
- expect(subject.matches_criteria?(:description => /request.*food/)).to be true
35
- end
36
- end
37
- context "when the interaction does not match" do
38
- it "returns false" do
39
- expect(subject.matches_criteria?(:description => /blah/)).to be false
40
- end
41
- end
42
- end
43
- end
44
-
45
- describe "from_hash" do
46
- context "when providerState has been used instead of provider_state" do
47
-
48
- subject { Interaction.from_hash('response' => response, 'request' => request, 'providerState' => 'some state') }
49
-
50
- it "recognises the provider state" do
51
- expect(subject.provider_state).to eq 'some state'
52
- end
53
- end
54
- end
55
-
56
- describe "to JSON" do
57
- let(:request) do
58
- {
59
- method: 'post',
60
- path: '/foo',
61
- body: Term.new(generate: 'waffle', matcher: /ffl/),
62
- headers: { 'Content-Type' => 'application/json' },
63
- query: '',
64
- }
65
- end
66
-
67
- let(:response) do
68
- { baz: /qux/, wiffle: Term.new(generate: 'wiffle', matcher: /iff/) }
69
- end
70
-
71
- let(:parsed_result) do
72
- JSON.load(subject.to_json)
73
- end
74
-
75
- subject { Interaction.from_hash('response' => response, 'request' => request) }
76
-
77
- it "contains the request" do
78
- expect(parsed_result['request']).to eq({
79
- 'method' => 'post',
80
- 'path' => '/foo',
81
- 'headers' => {
82
- 'Content-Type' => 'application/json'
83
- },
84
- 'body' => Term.new(generate: 'waffle', matcher: /ffl/),
85
- 'query' => ''
86
- })
87
- end
88
-
89
- describe "response" do
90
-
91
- it "serialises regexes" do
92
- expect(parsed_result['response']['baz']).to eql /qux/
93
- end
94
-
95
- it "serialises terms" do
96
- term = Term.new(generate:'wiffle', matcher: /iff/)
97
- parsed_term = parsed_result['response']['wiffle']
98
- expect(term.matcher).to eql parsed_term.matcher
99
- expect(term.generate).to eql parsed_term.generate
100
- end
101
-
102
- end
103
-
104
- end
105
- end
106
- end
107
- end
@@ -1,329 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer_contract/request'
3
- require 'pact/consumer/request'
4
- require 'support/shared_examples_for_request'
5
-
6
- module Pact
7
-
8
- describe Request::Expected do
9
- it_behaves_like "a request"
10
-
11
- let(:raw_request) do
12
- {
13
- 'method' => 'get',
14
- 'path' => '/mallory'
15
- }
16
- end
17
-
18
- describe "from_hash" do
19
- context "when optional field are not defined" do
20
- subject { described_class.from_hash(raw_request) }
21
- it "sets their values to NullExpectation" do
22
- expect(subject.body).to be_instance_of(Pact::NullExpectation)
23
- expect(subject.query).to be_instance_of(Pact::NullExpectation)
24
- expect(subject.headers).to be_instance_of(Pact::NullExpectation)
25
- end
26
- end
27
- end
28
-
29
- describe "as_json" do
30
- subject { Request::Expected.new(:get, '/path', {:header => 'value'}, {:body => 'yeah'}, "query", {some: 'options'}) }
31
- context "with options" do
32
- it "does not include the options because they are a temporary hack and should leave no trace of themselves in the pact file" do
33
- expect(subject.as_json.key?(:options)).to be false
34
- end
35
- end
36
- end
37
-
38
- describe "matching to actual requests" do
39
-
40
- subject { Request::Expected.new(expected_method, expected_path, expected_headers, expected_body, expected_query, options) }
41
- let(:options) { {} }
42
-
43
- let(:expected_method) { 'get' }
44
- let(:expected_path) { '/foo' }
45
- let(:expected_headers) { Pact::NullExpectation.new }
46
- let(:expected_body) { Pact::NullExpectation.new }
47
- let(:expected_query) { '' }
48
-
49
- let(:actual_request) { Consumer::Request::Actual.new(actual_method, actual_path, actual_headers, actual_body, actual_query) }
50
-
51
- let(:actual_method) { 'get' }
52
- let(:actual_path) { '/foo' }
53
- let(:actual_headers) { {} }
54
- let(:actual_body) { '' }
55
- let(:actual_query) { '' }
56
-
57
- it "matches identical requests" do
58
- expect(subject.matches? actual_request).to be true
59
- end
60
-
61
- context "when the methods are the same but one is symbolized" do
62
- let(:expected_method) { :get }
63
- let(:actual_method) { 'get' }
64
-
65
- it "matches" do
66
- expect(subject.matches? actual_request).to be true
67
- end
68
- end
69
-
70
- context "when the methods are different" do
71
- let(:expected_method) { 'get' }
72
- let(:actual_method) { 'post' }
73
-
74
- it "does not match" do
75
- expect(subject.matches? actual_request).to be false
76
- end
77
- end
78
-
79
- context "when the methods are the same but different case" do
80
- let(:expected_method) { 'get' }
81
- let(:actual_method) { 'GET' }
82
-
83
- it "matches" do
84
- expect(subject.matches? actual_request).to be true
85
- end
86
- end
87
-
88
- context "when the paths are different" do
89
- let(:expected_path) { '/foo' }
90
- let(:actual_path) { '/bar' }
91
-
92
- it "does not match" do
93
- expect(subject.matches? actual_request).to be false
94
- end
95
- end
96
-
97
- context "when the paths vary only by a trailing slash" do
98
- let(:expected_path) { '/foo' }
99
- let(:actual_path) { '/foo/' }
100
-
101
- it "matches" do
102
- expect(subject.matches? actual_request).to be true
103
- end
104
- end
105
-
106
- context "when the expected body is nil and the actual body is empty" do
107
- let(:expected_body) { nil }
108
- let(:actual_body) { '' }
109
-
110
- it "does not match" do
111
- expect(subject.matches? actual_request).to be false
112
- end
113
- end
114
-
115
- context "when the expected body has no expectation and the actual body is empty" do
116
- let(:expected_body) { Pact::NullExpectation.new }
117
- let(:actual_body) { '' }
118
-
119
- it "matches" do
120
- expect(subject.matches? actual_request).to be true
121
- end
122
- end
123
-
124
- context "when the expected body is nested and the actual body is nil" do
125
- let(:expected_body) do
126
- {
127
- a: 'a'
128
- }
129
- end
130
-
131
- let(:actual_body) { nil }
132
-
133
- it "does not match" do
134
- expect(subject.matches? actual_request).to be false
135
- end
136
- end
137
-
138
- context "when the bodies are different" do
139
- let(:expected_body) { 'foo' }
140
- let(:actual_body) { 'bar' }
141
-
142
- it "does not match" do
143
- expect(subject.matches? actual_request).to be false
144
- end
145
- end
146
-
147
- context "when the expected body contains matching regexes" do
148
- let(:expected_body) do
149
- {
150
- name: 'Bob',
151
- customer_id: /CN.*/
152
- }
153
- end
154
-
155
- let(:actual_body) do
156
- {
157
- name: 'Bob',
158
- customer_id: 'CN1234'
159
- }
160
- end
161
-
162
- it "matches" do
163
- expect(subject.matches? actual_request).to be true
164
- end
165
- end
166
-
167
- context "when the expected body contains non-matching regexes" do
168
- let(:expected_body) do
169
- {
170
- name: 'Bob',
171
- customer_id: /foo/
172
- }
173
- end
174
-
175
- let(:actual_body) do
176
- {
177
- name: 'Bob',
178
- customer_id: 'CN1234'
179
- }
180
- end
181
-
182
- it "does not match" do
183
- expect(subject.matches? actual_request).to be false
184
- end
185
- end
186
-
187
- context "when the expected body contains matching terms" do
188
- let(:expected_body) do
189
- {
190
- name: 'Bob',
191
- customer_id: Term.new(matcher: /CN.*/, generate: 'CN789')
192
- }
193
- end
194
-
195
- let(:actual_body) do
196
- {
197
- name: 'Bob',
198
- customer_id: 'CN1234'
199
- }
200
- end
201
-
202
- it "matches" do
203
- expect(subject.matches? actual_request).to be true
204
- end
205
- end
206
-
207
- context "when the expected body contains non-matching terms" do
208
- let(:expected_body) do
209
- {
210
- name: 'Bob',
211
- customer_id: Term.new(matcher: /foo/, generate: 'fooool')
212
- }
213
- end
214
-
215
- let(:actual_body) do
216
- {
217
- name: 'Bob',
218
- customer_id: 'CN1234'
219
- }
220
- end
221
-
222
- it "does not match" do
223
- expect(subject.matches? actual_request).to be false
224
- end
225
- end
226
-
227
- context "when the expected body contains non-matching arrays" do
228
- let(:expected_body) do
229
- {
230
- name: 'Robert',
231
- nicknames: ['Bob', 'Bobert']
232
- }
233
- end
234
-
235
- let(:actual_body) do
236
- {
237
- name: 'Bob',
238
- nicknames: ['Bob']
239
- }
240
- end
241
-
242
- it "does not match" do
243
- expect(subject.matches? actual_request).to be false
244
- end
245
- end
246
- context "when the expected body contains non-matching hash where one field contains a substring of the other" do
247
- let(:expected_body) do
248
- {
249
- name: 'Robert',
250
- }
251
- end
252
-
253
- let(:actual_body) do
254
- {
255
- name: 'Rob'
256
- }
257
- end
258
-
259
- it "does not match" do
260
- expect(subject.matches? actual_request).to be false
261
- end
262
- end
263
-
264
- context "when the expected body contains matching arrays" do
265
- let(:expected_body) do
266
- {
267
- name: 'Robert',
268
- nicknames: ['Bob', 'Bobert']
269
- }
270
- end
271
-
272
- let(:actual_body) do
273
- {
274
- name: 'Robert',
275
- nicknames: ['Bob', 'Bobert']
276
- }
277
- end
278
-
279
- it "does not match" do
280
- expect(subject.matches? actual_request).to be true
281
- end
282
- end
283
-
284
- context "when the queries are different" do
285
- let(:expected_query) { 'foo' }
286
- let(:actual_query) { 'bar' }
287
-
288
- it "does not match" do
289
- expect(subject.matches? actual_request).to be false
290
- end
291
- end
292
-
293
- context 'when there is no query expectation' do
294
- let(:expected_query) { Pact::NullExpectation.new }
295
- let(:actual_query) { 'bar' }
296
-
297
- it 'matches' do
298
- expect(subject.matches? actual_request).to be true
299
- end
300
- end
301
-
302
- context "when a string is expected, but a number is found" do
303
- let(:actual_body) { { thing: 123} }
304
- let(:expected_body) { { thing: "123" } }
305
-
306
- it 'does not match' do
307
- expect(subject.matches? actual_request).to be false
308
- end
309
- end
310
-
311
- context "when unexpected keys are found in the body" do
312
- let(:expected_body) { {a: 1} }
313
- let(:actual_body) { {a: 1, b: 2} }
314
- context "when allowing unexpected keys" do
315
- let(:options) { {'allow_unexpected_keys_in_body' => true} } #From json, these will be strings
316
- it "matches" do
317
- expect(subject.matches? actual_request).to be true
318
- end
319
- end
320
- context "when not allowing unexpected keys" do
321
- let(:options) { {'allow_unexpected_keys_in_body' => false} }
322
- it "does not match" do
323
- expect(subject.matches? actual_request).to be false
324
- end
325
- end
326
- end
327
- end
328
- end
329
- end
@@ -1,214 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # Ripped from spec/rspec/expectations/differ_spec.rb in rspec-expectations 2.14.3
4
-
5
- require 'spec_helper'
6
- require 'ostruct'
7
-
8
- module Pact
9
- module Matchers
10
- describe Differ do
11
- context "without --color" do
12
-
13
- let(:differ) { Pact::Matchers::Differ.new }
14
-
15
- # color disabled context
16
-
17
- describe '#diff_as_string' do
18
- subject { differ.diff_as_string(@expected, @actual) }
19
- it "outputs unified diff of two strings" do
20
- @expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
21
- @actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
22
- expect(subject).to eql(<<-'EOD')
23
-
24
-
25
- @@ -1,6 +1,6 @@
26
- foo
27
- -zap
28
- bar
29
- +zap
30
- this
31
- is
32
- soo
33
- @@ -9,6 +9,5 @@
34
- equal
35
- insert
36
- a
37
- -another
38
- line
39
- EOD
40
-
41
- end
42
- if RUBY_VERSION.to_f > 1.9
43
- it 'copes with encoded strings', :pending => (Diff::LCS::VERSION < '1.2.2') do
44
- @expected="Tu avec carté {count} itém has".encode('UTF-16LE')
45
- @actual="Tu avec carte {count} item has".encode('UTF-16LE')
46
- expect(subject).to eql(<<-EOD.encode('UTF-16LE'))
47
-
48
- @@ -1,2 +1,2 @@
49
- -Tu avec carte {count} item has
50
- +Tu avec carté {count} itém has
51
- EOD
52
- end
53
- it 'copes with encoded strings', :pending => (Diff::LCS::VERSION >= '1.2.2') do
54
- @expected="Tu avec carté {count} itém has".encode('UTF-16LE')
55
- @actual="Tu avec carte {count} item has".encode('UTF-16LE')
56
- expect(subject).to eql 'Could not produce a diff because of the encoding of the string (UTF-16LE)'
57
- end
58
- it 'ouputs a message when encountering differently encoded strings' do
59
- @expected="Tu avec carté {count} itém has".encode('UTF-16LE')
60
- @actual="Tu avec carte {count} item has"
61
- expect(subject).to eql 'Could not produce a diff because the encoding of the actual string (UTF-8) differs from the encoding of the expected string (UTF-16LE)'
62
- end
63
- end
64
- end
65
-
66
- describe '#diff_as_object' do
67
- it "outputs unified diff message of two objects" do
68
- animal_class = Class.new do
69
- def initialize(name, species)
70
- @name, @species = name, species
71
- end
72
-
73
- def inspect
74
- <<-EOA
75
- <Animal
76
- name=#{@name},
77
- species=#{@species}
78
- >
79
- EOA
80
- end
81
- end
82
-
83
- expected = animal_class.new "bob", "giraffe"
84
- actual = animal_class.new "bob", "tortoise"
85
-
86
- expected_diff = <<'EOD'
87
-
88
- @@ -1,5 +1,5 @@
89
- <Animal
90
- name=bob,
91
- - species=tortoise
92
- + species=giraffe
93
- >
94
- EOD
95
-
96
- diff = differ.diff_as_object(expected,actual)
97
- expect(diff).to eq expected_diff
98
- end
99
-
100
- it "outputs unified diff message of two arrays" do
101
- expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
102
- actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
103
-
104
- expected_diff = <<'EOD'
105
-
106
-
107
- @@ -5,7 +5,7 @@
108
- :metasyntactic,
109
- "variable",
110
- :delta,
111
- - "tango",
112
- + "charlie",
113
- :width,
114
- - "very wide"]
115
- + "quite wide"]
116
- EOD
117
-
118
- diff = differ.diff_as_object(expected,actual)
119
- expect(diff).to eq expected_diff
120
- end
121
-
122
- it "outputs unified diff message of two hashes" do
123
- expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' }
124
- actual = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' }
125
-
126
- expected_diff = <<'EOD'
127
-
128
- @@ -1,4 +1,5 @@
129
- -:delta => "charlotte",
130
- +:baz => "quux",
131
- +:delta => "charlie",
132
- :foo => "bar",
133
- :metasyntactic => "variable",
134
- :width => "quite wide"
135
- EOD
136
-
137
- diff = differ.diff_as_object(expected,actual)
138
- expect(diff).to eq expected_diff
139
- end
140
-
141
- it 'outputs unified diff messaoge of two hashes with differing encoding' do
142
- expected_diff = %Q{
143
- @@ -1,2 +1,2 @@
144
- -"a" => "a"
145
- #{ (RUBY_VERSION.to_f > 1.8) ? %Q{+"ö" => "ö"} : '+"\303\266" => "\303\266"' }
146
- }
147
-
148
- diff = differ.diff_as_object({'ö' => 'ö'}, {'a' => 'a'})
149
- expect(diff).to eq expected_diff
150
- end
151
-
152
- it "outputs unified diff message of two hashes with object keys" do
153
- expected_diff = %Q{
154
- @@ -1,2 +1,2 @@
155
- -["a", "c"] => "b"
156
- +["d", "c"] => "b"
157
- }
158
-
159
- diff = differ.diff_as_object({ ['d','c'] => 'b'}, { ['a','c'] => 'b' })
160
- expect(diff).to eq expected_diff
161
- end
162
-
163
- it "outputs unified diff of single line strings" do
164
- expected = "this is one string"
165
- actual = "this is another string"
166
-
167
- expected_diff = <<'EOD'
168
-
169
- @@ -1,2 +1,2 @@
170
- -"this is another string"
171
- +"this is one string"
172
- EOD
173
-
174
- diff = differ.diff_as_object(expected,actual)
175
- expect(diff).to eq expected_diff
176
- end
177
-
178
- it "outputs unified diff of multi line strings" do
179
- expected = "this is:\n one string"
180
- actual = "this is:\n another string"
181
-
182
- expected_diff = <<'EOD'
183
-
184
- @@ -1,3 +1,3 @@
185
- this is:
186
- - another string
187
- + one string
188
- EOD
189
-
190
- diff = differ.diff_as_object(expected,actual)
191
- expect(diff).to eq expected_diff
192
- end
193
- end
194
- end
195
-
196
- context "with --color" do
197
-
198
- let(:differ) { Pact::Matchers::Differ.new(true) }
199
-
200
- it "outputs colored diffs" do
201
- expected = "foo bar baz"
202
- actual = "foo bang baz"
203
- expected_diff = "\n\e[34m@@ -1,2 +1,2 @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"
204
-
205
-
206
- diff = differ.diff_as_string(expected,actual)
207
- expect(diff).to eq expected_diff
208
- end
209
- end
210
-
211
- end
212
- end
213
- end
214
-