pact 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,14 @@
1
- ### 1.0.7 (11 September 2012)
1
+ ### 1.0.8 (13 September 2013)
2
+
3
+ * Added validation to ensure that a Term has both a matcher and a generate value, and that the value to generate matches the given regular expression [Beth Skurrie]
4
+
5
+ * Added the SomethingLike class that does a structure diff on anything contianed within in it. Will change the name when we can think of something better! [Beth Skurrie, Greg Dziemidowicz]
6
+
7
+ ### 1.0.7 (11 September 2013)
2
8
 
3
9
  * Allow request query to be a Pact Term. [Seb Glazebrook]
4
10
 
5
- ### 1.0.6 (11 September 2012)
11
+ ### 1.0.6 (11 September 2013)
6
12
 
7
13
  * Made reports dir configurable [Beth Skurrie]
8
14
  * Changed the way the pact files are configured. They are now in the Pact.service_provider block in the pact_helper file. Require 'pact/tasks' in the Rakefile and run 'rake pact:verify' instead of setting up custom tasks. [Beth Skurrie]
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact (1.0.7)
4
+ pact (1.0.8)
5
5
  awesome_print (~> 1.1.0)
6
6
  find_a_port (~> 1.0.1)
7
7
  hashie (~> 2.0)
@@ -7,4 +7,5 @@ require_relative 'consumer/mock_service'
7
7
  require_relative 'consumer/mock_service_client'
8
8
  require_relative 'consumer/app_manager'
9
9
  require_relative 'term'
10
+ require_relative 'something_like'
10
11
  require_relative 'request'
@@ -4,6 +4,8 @@ require 'pact/json_warning'
4
4
  require 'date'
5
5
  require 'pact/version'
6
6
  require 'open-uri'
7
+ require 'pact/term'
8
+ require 'pact/something_like'
7
9
  require_relative 'service_consumer'
8
10
  require_relative 'service_provider'
9
11
  require_relative 'interaction'
@@ -33,6 +33,7 @@ module Pact
33
33
  when Array then array_diff(expected, actual, options)
34
34
  when Pact::Term then diff(expected.matcher, actual, options)
35
35
  when Regexp then regexp_diff(expected, actual, options)
36
+ when Pact::SomethingLike then diff(expected.contents, actual, options.merge(:structure => true))
36
37
  else object_diff(expected, actual, options)
37
38
  end
38
39
  end
@@ -1,4 +1,3 @@
1
1
  require 'pact/configuration'
2
2
  require 'pact/provider/dsl'
3
- require 'pact/provider/client_project_pact_helper'
4
3
  require 'pact/provider/pact_spec_runner'
@@ -1,4 +1,5 @@
1
1
  require 'pact/matchers'
2
+ require 'pact/reification'
2
3
 
3
4
  module Pact
4
5
 
@@ -0,0 +1,31 @@
1
+ module Pact
2
+
3
+ class SomethingLike
4
+ attr_reader :contents
5
+
6
+ def initialize contents
7
+ @contents = contents
8
+ end
9
+
10
+ def as_json
11
+ {
12
+ :json_class => self.class.name,
13
+ :contents => contents
14
+ }
15
+ end
16
+
17
+ def to_json opts = {}
18
+ as_json.to_json opts
19
+ end
20
+
21
+ def self.json_create hash
22
+ new(hash['contents'])
23
+ end
24
+
25
+ def generate
26
+ contents
27
+ end
28
+ end
29
+ end
30
+
31
+
@@ -10,6 +10,9 @@ module Pact
10
10
  def initialize(attributes = {})
11
11
  @generate = attributes[:generate]
12
12
  @matcher = attributes[:matcher]
13
+ raise "Please specify a matcher for the Term" unless @matcher != nil
14
+ raise "Please specify a value to generate for the Term" unless @generate != nil
15
+ raise "Value to generate \"#{@generate}\" does not match regular expression #{@matcher}" unless @generate =~ @matcher
13
16
  end
14
17
 
15
18
  def to_json(options = {})
@@ -37,7 +40,7 @@ module Pact
37
40
  end
38
41
 
39
42
  def empty?
40
- generate ? false : true
43
+ false
41
44
  end
42
45
 
43
46
  end
@@ -1,3 +1,3 @@
1
1
  module Pact
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
@@ -5,6 +5,7 @@ namespace :pact do
5
5
  task :verify do
6
6
  require 'pact/provider'
7
7
  require 'pact/pact_task_helper'
8
+ require 'pact/provider/client_project_pact_helper'
8
9
 
9
10
  include PactTaskHelper
10
11
 
@@ -39,7 +39,7 @@ describe "A service consumer side of a pact", :pact => true do
39
39
  method: :post,
40
40
  path: '/donuts',
41
41
  body: {
42
- "name" => Pact::Term.new(matcher: /Bob/)
42
+ "name" => Pact::Term.new(matcher: /Bob/, generate: 'Bob')
43
43
  },
44
44
  headers: {'Accept' => 'text/plain', "Content-Type" => 'application/json'}
45
45
  }).
@@ -56,7 +56,7 @@ describe "A service consumer side of a pact", :pact => true do
56
56
  status: 200,
57
57
  body: /deleted/
58
58
  })
59
- bob_service.
59
+ bob_service.
60
60
  upon_receiving('an update alligators request').with({
61
61
  method: :put,
62
62
  path: '/alligators',
@@ -1,10 +1,25 @@
1
1
  require 'spec_helper'
2
2
  require 'pact/term'
3
+ require 'pact/something_like'
3
4
  require 'pact/matchers'
4
5
 
5
6
  describe Pact::Matchers do
6
7
  include Pact::Matchers
7
8
 
9
+ describe 'matching with something like' do
10
+
11
+ context 'when the actual is something like the expected' do
12
+ let(:expected) { Pact::SomethingLike.new( { a: 1 } ) }
13
+ let(:actual) { { a: 2} }
14
+
15
+ it 'returns an empty diff' do
16
+ expect(diff(expected, actual)).to eq({})
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
8
23
  describe 'option {allow_unexpected_keys: false}' do
9
24
  context "when an unexpected key is found" do
10
25
  let(:expected) { {:a => 1} }
@@ -314,7 +329,7 @@ describe Pact::Matchers do
314
329
  end
315
330
 
316
331
  context "a deep mismatch" do
317
- subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/)}}, f: 1, g: {h: 99}} }
332
+ subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/, generate: 'apple')}}, f: 1, g: {h: 99}} }
318
333
  let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} }
319
334
  let(:difference) { {:a=>{:d=>{:e=>{:expected=>/a/, :actual=>"food"}}}, :f=>{:expected=>1, :actual=>"thing"}, :g=>{:expected=>{:h=>99}, :actual=> Pact::Matchers::KeyNotFound.new}} }
320
335
 
@@ -325,7 +340,7 @@ describe Pact::Matchers do
325
340
 
326
341
 
327
342
  context "where a Pact::Term is found that matches the actual value" do
328
- subject { {:a => Pact::Term.new(:matcher => /a/)} }
343
+ subject { {:a => Pact::Term.new(:matcher => /a/, :generate => 'apple')} }
329
344
  let(:actual) { {:a => "apple" } }
330
345
 
331
346
  it 'does not include this in the diff' do
@@ -371,7 +386,7 @@ describe Pact::Matchers do
371
386
  end
372
387
 
373
388
  context "when an array that matches the Pact::Term is found" do
374
- subject { [Pact::Term.new(:matcher => /4/),"5","6"] }
389
+ subject { [Pact::Term.new(:matcher => /4/, :generate => '4'),"5","6"] }
375
390
  let(:actual) { ["4","5","6"] }
376
391
 
377
392
  it 'includes this in the diff' do
@@ -38,7 +38,7 @@ module Pact::Provider
38
38
 
39
39
  context 'Term query' do
40
40
 
41
- let(:query) { Pact::Term.new(generate: 'query') }
41
+ let(:query) { Pact::Term.new(generate: 'query', matcher: /q/) }
42
42
 
43
43
  it 'appends the Term\'s generate to the path' do
44
44
  expect(@path).to eq('path?query')
@@ -251,7 +251,7 @@ module Pact
251
251
  let(:expected_body) do
252
252
  {
253
253
  name: 'Bob',
254
- customer_id: Term.new(matcher: /CN.*/)
254
+ customer_id: Term.new(matcher: /CN.*/, generate: 'CN789')
255
255
  }
256
256
  end
257
257
 
@@ -271,7 +271,7 @@ module Pact
271
271
  let(:expected_body) do
272
272
  {
273
273
  name: 'Bob',
274
- customer_id: Term.new(matcher: /foo/)
274
+ customer_id: Term.new(matcher: /foo/, generate: 'fooool')
275
275
  }
276
276
  end
277
277
 
@@ -3,6 +3,38 @@ require 'spec_helper'
3
3
  module Pact
4
4
  describe Term do
5
5
 
6
+ describe 'initialize' do
7
+ let(:matcher) { /e/ }
8
+ let(:generate) { 'apple'}
9
+ subject { Term.new(generate: generate, matcher: matcher) }
10
+ context "when a matcher and generate are specified" do
11
+ context "when the matcher matches the generated value" do
12
+ it 'does not raise an exception' do
13
+ subject
14
+ end
15
+ end
16
+
17
+ context "when the matcher does not match the generated value" do
18
+ let(:generate) { 'banana' }
19
+ it 'raises an exception' do
20
+ expect { subject }.to raise_error /does not match/
21
+ end
22
+ end
23
+ end
24
+ context 'when a matcher is not specified' do
25
+ let(:matcher) { nil }
26
+ it 'raises an exception' do
27
+ expect { subject }.to raise_error /Please specify a matcher/
28
+ end
29
+ end
30
+ context 'when a generate is not specified' do
31
+ let(:generate) { nil }
32
+ it 'raises an exception' do
33
+ expect { subject }.to raise_error /Please specify a value/
34
+ end
35
+ end
36
+ end
37
+
6
38
  describe "equality" do
7
39
  context "when the matcher and generate attrs are the same" do
8
40
  let(:this) { Term.new(generate: 'A', matcher: /A/) }
@@ -14,8 +46,8 @@ module Pact
14
46
  end
15
47
 
16
48
  context "when the generate attrs are different" do
17
- let(:this) { Term.new(generate: /A/) }
18
- let(:that) { Term.new(generate: /B/) }
49
+ let(:this) { Term.new(generate: 'A', matcher: /.*/) }
50
+ let(:that) { Term.new(generate: 'B', matcher: /.*/) }
19
51
 
20
52
  it "is not equal" do
21
53
  expect(this).to_not eq that
@@ -23,8 +55,8 @@ module Pact
23
55
  end
24
56
 
25
57
  context "when the matcher attrs are different" do
26
- let(:this) { Term.new(matcher: 'A') }
27
- let(:that) { Term.new(matcher: 'B') }
58
+ let(:this) { Term.new(matcher: /A/, generate: 'AB') }
59
+ let(:that) { Term.new(matcher: /B/, generate: 'AB') }
28
60
 
29
61
  it "is not equal" do
30
62
  expect(this).to_not eq that
@@ -34,25 +66,10 @@ module Pact
34
66
 
35
67
  describe 'empty?' do
36
68
 
37
- subject { Term.new(generate: generate, matcher: /some matcher/) }
69
+ subject { Term.new(generate: 'some', matcher: /some/) }
38
70
 
39
- context 'with generate' do
40
-
41
- let(:generate) { 'generate here'}
42
-
43
- it 'is not empty' do
44
- expect(subject).to_not be_empty
45
- end
46
-
47
- end
48
-
49
- context 'without generate' do
50
-
51
- let(:generate) { nil }
52
-
53
- it 'is empty' do
54
- expect(subject).to be_empty
55
- end
71
+ it 'should return false' do
72
+ expect(subject).to_not be_empty
56
73
  end
57
74
 
58
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -305,6 +305,7 @@ files:
305
305
  - lib/pact/provider/verification_report.rb
306
306
  - lib/pact/reification.rb
307
307
  - lib/pact/request.rb
308
+ - lib/pact/something_like.rb
308
309
  - lib/pact/tasks.rb
309
310
  - lib/pact/term.rb
310
311
  - lib/pact/verification_task.rb