pact-support 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,148 @@
1
+ require 'pact/matching_rules/merge'
2
+
3
+ module Pact
4
+ module MatchingRules
5
+ describe Merge do
6
+
7
+ subject { Merge.(expected, matching_rules, "$.body") }
8
+
9
+ before do
10
+ allow($stderr).to receive(:puts)
11
+ end
12
+
13
+ describe "no recognised rules" do
14
+ let(:expected) do
15
+ {
16
+ "_links" => {
17
+ "self" => {
18
+ "href" => "http://localhost:1234/thing"
19
+ }
20
+ }
21
+ }
22
+ end
23
+
24
+ let(:matching_rules) do
25
+ {
26
+ "$.body._links.self.href" => {"type" => "unknown" }
27
+ }
28
+ end
29
+
30
+ it "returns the object at that path unaltered" do
31
+ expect(subject["_links"]["self"]["href"]).to eq "http://localhost:1234/thing"
32
+ end
33
+
34
+ it "it logs the rules it has ignored" do
35
+ expect($stderr).to receive(:puts) do | message |
36
+ expect(message).to include("WARN")
37
+ expect(message).to include("type")
38
+ expect(message).to include("unknown")
39
+ expect(message).to include("$.body._links.self.href")
40
+ end
41
+ subject
42
+ end
43
+
44
+ end
45
+
46
+ describe "with nil rules" do
47
+ let(:expected) do
48
+ {
49
+ "_links" => {
50
+ "self" => {
51
+ "href" => "http://localhost:1234/thing"
52
+ }
53
+ }
54
+ }
55
+ end
56
+
57
+ let(:matching_rules) { nil }
58
+
59
+ it "returns the example unaltered" do
60
+ expect(subject["_links"]["self"]["href"]).to eq "http://localhost:1234/thing"
61
+ end
62
+
63
+ end
64
+
65
+ describe "type based matching" do
66
+ let(:expected) do
67
+ {
68
+ "name" => "Mary"
69
+ }
70
+ end
71
+
72
+ let(:matching_rules) do
73
+ {
74
+ "$.body.name" => { "match" => "type", "ignored" => "matchingrule" }
75
+ }
76
+ end
77
+
78
+ it "creates a SomethingLike at the appropriate path" do
79
+ expect(subject['name']).to be_instance_of(Pact::SomethingLike)
80
+ end
81
+
82
+ it "it logs the rules it has ignored" do
83
+ expect($stderr).to receive(:puts).with(/ignored.*matchingrule/)
84
+ subject
85
+ end
86
+
87
+ end
88
+
89
+ describe "regular expressions" do
90
+
91
+ describe "in a hash" do
92
+ let(:expected) do
93
+ {
94
+ "_links" => {
95
+ "self" => {
96
+ "href" => "http://localhost:1234/thing"
97
+ }
98
+ }
99
+ }
100
+ end
101
+
102
+ let(:matching_rules) do
103
+ {
104
+ "$.body._links.self.href" => { "regex" => "http:\\/\\/.*\\/thing", "match" => "regex", "ignored" => "somerule" }
105
+ }
106
+ end
107
+ it "creates a Pact::Term at the appropriate path" do
108
+ expect(subject["_links"]["self"]["href"]).to be_instance_of(Pact::Term)
109
+ expect(subject["_links"]["self"]["href"].generate).to eq "http://localhost:1234/thing"
110
+ expect(subject["_links"]["self"]["href"].matcher.inspect).to eq "/http:\\/\\/.*\\/thing/"
111
+ end
112
+ it "it logs the rules it has ignored" do
113
+ expect($stderr).to receive(:puts) do | message |
114
+ expect(message).to match /ignored.*"somerule"/
115
+ expect(message).to_not match /regex/
116
+ expect(message).to_not match /"match"/
117
+ end
118
+ subject
119
+ end
120
+ end
121
+
122
+ describe "with an array" do
123
+
124
+ let(:expected) do
125
+ {
126
+ "_links" => {
127
+ "self" => [{
128
+ "href" => "http://localhost:1234/thing"
129
+ }]
130
+ }
131
+ }
132
+ end
133
+
134
+ let(:matching_rules) do
135
+ {
136
+ "$.body._links.self[0].href" => { "regex" => "http:\\/\\/.*\\/thing" }
137
+ }
138
+ end
139
+ it "creates a Pact::Term at the appropriate path" do
140
+ expect(subject["_links"]["self"][0]["href"]).to be_instance_of(Pact::Term)
141
+ expect(subject["_links"]["self"][0]["href"].generate).to eq "http://localhost:1234/thing"
142
+ expect(subject["_links"]["self"][0]["href"].matcher.inspect).to eq "/http:\\/\\/.*\\/thing/"
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -5,6 +5,15 @@ module Pact
5
5
 
6
6
  extend self
7
7
 
8
+ def load_fixture name
9
+ File.read(File.join("./spec/fixtures", name))
10
+ end
11
+
12
+ def load_json_fixture name
13
+ require 'json'
14
+ JSON.parse(load_fixture(name))
15
+ end
16
+
8
17
  def remove_ansicolor string
9
18
  string.gsub(/\e\[(\d+)m/, '')
10
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -12,202 +12,202 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-01-20 00:00:00.000000000 Z
15
+ date: 2015-02-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: randexp
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ~>
21
+ - - "~>"
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.1.7
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - ~>
28
+ - - "~>"
29
29
  - !ruby/object:Gem::Version
30
30
  version: 0.1.7
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: rspec
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - '>='
35
+ - - ">="
36
36
  - !ruby/object:Gem::Version
37
37
  version: '2.14'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - '>='
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
44
  version: '2.14'
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: rack-test
47
47
  requirement: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - ~>
49
+ - - "~>"
50
50
  - !ruby/object:Gem::Version
51
51
  version: 0.6.2
52
52
  type: :runtime
53
53
  prerelease: false
54
54
  version_requirements: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - ~>
56
+ - - "~>"
57
57
  - !ruby/object:Gem::Version
58
58
  version: 0.6.2
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: awesome_print
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - ~>
63
+ - - "~>"
64
64
  - !ruby/object:Gem::Version
65
65
  version: '1.1'
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - ~>
70
+ - - "~>"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '1.1'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: json
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - '>='
77
+ - - ">="
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  type: :runtime
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - '>='
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: term-ansicolor
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ~>
91
+ - - "~>"
92
92
  - !ruby/object:Gem::Version
93
93
  version: '1.0'
94
94
  type: :runtime
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - ~>
98
+ - - "~>"
99
99
  - !ruby/object:Gem::Version
100
100
  version: '1.0'
101
101
  - !ruby/object:Gem::Dependency
102
102
  name: find_a_port
103
103
  requirement: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ~>
105
+ - - "~>"
106
106
  - !ruby/object:Gem::Version
107
107
  version: 1.0.1
108
108
  type: :runtime
109
109
  prerelease: false
110
110
  version_requirements: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - ~>
112
+ - - "~>"
113
113
  - !ruby/object:Gem::Version
114
114
  version: 1.0.1
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: thor
117
117
  requirement: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - '>='
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  type: :runtime
123
123
  prerelease: false
124
124
  version_requirements: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - '>='
126
+ - - ">="
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  - !ruby/object:Gem::Dependency
130
130
  name: rake
131
131
  requirement: !ruby/object:Gem::Requirement
132
132
  requirements:
133
- - - ~>
133
+ - - "~>"
134
134
  - !ruby/object:Gem::Version
135
135
  version: 10.0.3
136
136
  type: :development
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
- - - ~>
140
+ - - "~>"
141
141
  - !ruby/object:Gem::Version
142
142
  version: 10.0.3
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: webmock
145
145
  requirement: !ruby/object:Gem::Requirement
146
146
  requirements:
147
- - - ~>
147
+ - - "~>"
148
148
  - !ruby/object:Gem::Version
149
149
  version: 1.18.0
150
150
  type: :development
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
153
153
  requirements:
154
- - - ~>
154
+ - - "~>"
155
155
  - !ruby/object:Gem::Version
156
156
  version: 1.18.0
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: pry
159
159
  requirement: !ruby/object:Gem::Requirement
160
160
  requirements:
161
- - - '>='
161
+ - - ">="
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  type: :development
165
165
  prerelease: false
166
166
  version_requirements: !ruby/object:Gem::Requirement
167
167
  requirements:
168
- - - '>='
168
+ - - ">="
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
171
  - !ruby/object:Gem::Dependency
172
172
  name: fakefs
173
173
  requirement: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - ~>
175
+ - - "~>"
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0.4'
178
178
  type: :development
179
179
  prerelease: false
180
180
  version_requirements: !ruby/object:Gem::Requirement
181
181
  requirements:
182
- - - ~>
182
+ - - "~>"
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0.4'
185
185
  - !ruby/object:Gem::Dependency
186
186
  name: hashie
187
187
  requirement: !ruby/object:Gem::Requirement
188
188
  requirements:
189
- - - ~>
189
+ - - "~>"
190
190
  - !ruby/object:Gem::Version
191
191
  version: '2.0'
192
192
  type: :development
193
193
  prerelease: false
194
194
  version_requirements: !ruby/object:Gem::Requirement
195
195
  requirements:
196
- - - ~>
196
+ - - "~>"
197
197
  - !ruby/object:Gem::Version
198
198
  version: '2.0'
199
199
  - !ruby/object:Gem::Dependency
200
200
  name: activesupport
201
201
  requirement: !ruby/object:Gem::Requirement
202
202
  requirements:
203
- - - '>='
203
+ - - ">="
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
206
  type: :development
207
207
  prerelease: false
208
208
  version_requirements: !ruby/object:Gem::Requirement
209
209
  requirements:
210
- - - '>='
210
+ - - ">="
211
211
  - !ruby/object:Gem::Version
212
212
  version: '0'
213
213
  description:
@@ -221,9 +221,9 @@ executables: []
221
221
  extensions: []
222
222
  extra_rdoc_files: []
223
223
  files:
224
- - .gitignore
225
- - .rspec
226
- - .travis.yml
224
+ - ".gitignore"
225
+ - ".rspec"
226
+ - ".travis.yml"
227
227
  - CHANGELOG.md
228
228
  - Gemfile
229
229
  - LICENSE.txt
@@ -256,12 +256,15 @@ files:
256
256
  - lib/pact/matchers/index_not_found.rb
257
257
  - lib/pact/matchers/list_diff_formatter.rb
258
258
  - lib/pact/matchers/matchers.rb
259
- - lib/pact/matchers/no_diff_indicator.rb
259
+ - lib/pact/matchers/no_diff_at_index.rb
260
260
  - lib/pact/matchers/regexp_difference.rb
261
261
  - lib/pact/matchers/type_difference.rb
262
262
  - lib/pact/matchers/unexpected_index.rb
263
263
  - lib/pact/matchers/unexpected_key.rb
264
264
  - lib/pact/matchers/unix_diff_formatter.rb
265
+ - lib/pact/matching_rules.rb
266
+ - lib/pact/matching_rules/extract.rb
267
+ - lib/pact/matching_rules/merge.rb
265
268
  - lib/pact/reification.rb
266
269
  - lib/pact/rspec.rb
267
270
  - lib/pact/shared/active_support_support.rb
@@ -280,6 +283,8 @@ files:
280
283
  - lib/pact/term.rb
281
284
  - lib/tasks/pact.rake
282
285
  - pact-support.gemspec
286
+ - spec/fixtures/interaction-with-matching-rules.json
287
+ - spec/integration/matching_rules_extract_and_merge_spec.rb
283
288
  - spec/lib/pact/configuration_spec.rb
284
289
  - spec/lib/pact/consumer/request_spec.rb
285
290
  - spec/lib/pact/consumer_contract/active_support_support_spec.rb
@@ -296,12 +301,14 @@ files:
296
301
  - spec/lib/pact/matchers/index_not_found_spec.rb
297
302
  - spec/lib/pact/matchers/list_diff_formatter_spec.rb
298
303
  - spec/lib/pact/matchers/matchers_spec.rb
299
- - spec/lib/pact/matchers/no_diff_indicator_spec.rb
304
+ - spec/lib/pact/matchers/no_diff_at_index_spec.rb
300
305
  - spec/lib/pact/matchers/regexp_difference_spec.rb
301
306
  - spec/lib/pact/matchers/type_difference_spec.rb
302
307
  - spec/lib/pact/matchers/unexpected_index_spec.rb
303
308
  - spec/lib/pact/matchers/unexpected_key_spec.rb
304
309
  - spec/lib/pact/matchers/unix_diff_formatter_spec.rb
310
+ - spec/lib/pact/matching_rules/extract_spec.rb
311
+ - spec/lib/pact/matching_rules/merge_spec.rb
305
312
  - spec/lib/pact/reification_spec.rb
306
313
  - spec/lib/pact/shared/dsl_spec.rb
307
314
  - spec/lib/pact/shared/form_differ_spec.rb
@@ -344,21 +351,23 @@ require_paths:
344
351
  - lib
345
352
  required_ruby_version: !ruby/object:Gem::Requirement
346
353
  requirements:
347
- - - '>='
354
+ - - ">="
348
355
  - !ruby/object:Gem::Version
349
356
  version: '0'
350
357
  required_rubygems_version: !ruby/object:Gem::Requirement
351
358
  requirements:
352
- - - '>='
359
+ - - ">="
353
360
  - !ruby/object:Gem::Version
354
361
  version: '0'
355
362
  requirements: []
356
363
  rubyforge_project:
357
- rubygems_version: 2.0.14
364
+ rubygems_version: 2.2.2
358
365
  signing_key:
359
366
  specification_version: 4
360
367
  summary: Shared code for Pact gems
361
368
  test_files:
369
+ - spec/fixtures/interaction-with-matching-rules.json
370
+ - spec/integration/matching_rules_extract_and_merge_spec.rb
362
371
  - spec/lib/pact/configuration_spec.rb
363
372
  - spec/lib/pact/consumer/request_spec.rb
364
373
  - spec/lib/pact/consumer_contract/active_support_support_spec.rb
@@ -375,12 +384,14 @@ test_files:
375
384
  - spec/lib/pact/matchers/index_not_found_spec.rb
376
385
  - spec/lib/pact/matchers/list_diff_formatter_spec.rb
377
386
  - spec/lib/pact/matchers/matchers_spec.rb
378
- - spec/lib/pact/matchers/no_diff_indicator_spec.rb
387
+ - spec/lib/pact/matchers/no_diff_at_index_spec.rb
379
388
  - spec/lib/pact/matchers/regexp_difference_spec.rb
380
389
  - spec/lib/pact/matchers/type_difference_spec.rb
381
390
  - spec/lib/pact/matchers/unexpected_index_spec.rb
382
391
  - spec/lib/pact/matchers/unexpected_key_spec.rb
383
392
  - spec/lib/pact/matchers/unix_diff_formatter_spec.rb
393
+ - spec/lib/pact/matching_rules/extract_spec.rb
394
+ - spec/lib/pact/matching_rules/merge_spec.rb
384
395
  - spec/lib/pact/reification_spec.rb
385
396
  - spec/lib/pact/shared/dsl_spec.rb
386
397
  - spec/lib/pact/shared/form_differ_spec.rb
@@ -412,3 +423,4 @@ test_files:
412
423
  - spec/support/test_app_fail.json
413
424
  - spec/support/test_app_pass.json
414
425
  - spec/support/test_app_with_right_content_type_differ.json
426
+ has_rdoc: