pact 1.1.0.rc4 → 1.1.0.rc5

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact (1.1.0.rc4)
4
+ pact (1.1.0.rc5)
5
5
  awesome_print (~> 1.1)
6
6
  find_a_port (~> 1.0.1)
7
7
  json
@@ -20,11 +20,11 @@ module Pact
20
20
  DEFAULT_OPTIONS = {allow_unexpected_keys: true, type: false}.freeze
21
21
 
22
22
  def diff expected, actual, opts = {}
23
- calculate_diff(expected, actual, DEFAULT_OPTIONS.merge(opts))
23
+ calculate_diff(Pact::Term.unpack_regexps(expected), actual, DEFAULT_OPTIONS.merge(opts))
24
24
  end
25
25
 
26
26
  def type_diff expected, actual, opts = {}
27
- calculate_diff expected, actual, DEFAULT_OPTIONS.merge(opts).merge(type: true)
27
+ calculate_diff Pact::Term.unpack_regexps(expected), actual, DEFAULT_OPTIONS.merge(opts).merge(type: true)
28
28
  end
29
29
 
30
30
  private
@@ -34,7 +34,6 @@ module Pact
34
34
  case expected
35
35
  when Hash then hash_diff(expected, actual, options)
36
36
  when Array then array_diff(expected, actual, options)
37
- when Pact::Term then calculate_diff(expected.matcher, actual, options)
38
37
  when Regexp then regexp_diff(expected, actual, options)
39
38
  when Pact::SomethingLike then calculate_diff(expected.contents, actual, options.merge(:type => true))
40
39
  else object_diff(expected, actual, options)
@@ -71,9 +71,9 @@ module Pact
71
71
 
72
72
  def copy_diff difference, target
73
73
  if target == :actual
74
- copy_object difference.actual, target
74
+ handle difference.actual, target
75
75
  else
76
- copy_object difference.expected, target
76
+ handle difference.expected, target
77
77
  end
78
78
  end
79
79
 
@@ -18,9 +18,9 @@ module Pact
18
18
  request = Request::Replayable.new(interaction.request)
19
19
  args = [request.path, request.body, request.headers]
20
20
 
21
- logger.info "Sending #{request.method} request to path: \"#{request.path}\" with headers: #{request.headers}, see debug logs for body"
21
+ logger.info "Sending #{request.method.upcase} request to path: \"#{request.path}\" with headers: #{request.headers}, see debug logs for body"
22
22
  logger.debug "body :#{request.body}"
23
- response = self.send(request.method, *args)
23
+ response = self.send(request.method.downcase, *args)
24
24
  logger.info "Received response with status: #{response.status}, headers: #{response.headers}, see debug logs for body"
25
25
  logger.debug "body: #{response.body}"
26
26
  end
data/lib/pact/term.rb CHANGED
@@ -12,6 +12,16 @@ module Pact
12
12
  new(generate: obj['data']['generate'], matcher: obj['data']['matcher'])
13
13
  end
14
14
 
15
+ def self.unpack_regexps source
16
+ case source
17
+ when Pact::Term then source.matcher
18
+ when Array then unpack_regexps_from_array source
19
+ when Hash then unpack_regexps_from_hash source
20
+ else
21
+ source
22
+ end
23
+ end
24
+
15
25
  def initialize(attributes = {})
16
26
  @generate = attributes[:generate]
17
27
  @matcher = attributes[:matcher]
@@ -57,5 +67,19 @@ module Pact
57
67
  false
58
68
  end
59
69
 
70
+ private
71
+
72
+ def self.unpack_regexps_from_array source
73
+ source.each_with_object([]) do | item, destination |
74
+ destination << unpack_regexps(item)
75
+ end
76
+ end
77
+
78
+ def self.unpack_regexps_from_hash source
79
+ source.keys.each_with_object({}) do | key, destination |
80
+ destination[key] = unpack_regexps source[key]
81
+ end
82
+ end
83
+
60
84
  end
61
85
  end
data/lib/pact/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pact
2
- VERSION = "1.1.0.rc4"
2
+ VERSION = "1.1.0.rc5"
3
3
  end
@@ -22,9 +22,12 @@ module Pact
22
22
 
23
23
  describe ".call" do
24
24
 
25
- let(:colour) { true }
25
+ let(:colour) { false }
26
26
 
27
27
  context "when color_enabled is true" do
28
+
29
+ let(:colour) { true }
30
+
28
31
  it "returns nicely formatted json" do
29
32
  expect(subject.split("\n").size).to eq 6
30
33
  end
@@ -49,6 +52,16 @@ module Pact
49
52
  end
50
53
  end
51
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
+
52
65
  context "when no options are specified" do
53
66
  subject { EmbeddedDiffFormatter.call(diff) }
54
67
 
@@ -144,6 +144,17 @@ module Pact::Matchers
144
144
  end
145
145
  end
146
146
 
147
+ context "when a term is expected inside a missing hash" do
148
+ let(:expected) { {a: {b: Pact::Term.new(:matcher => /p/, :generate => 'apple')}} }
149
+ context "and a non matching value is found" do
150
+ let(:actual) { {a: nil} }
151
+ let(:difference) { {a: Difference.new({b: /p/}, nil)} }
152
+ it "returns the diff with the regexp unpacked" do
153
+ expect(type_diff(expected, actual)).to eq difference
154
+ end
155
+ end
156
+ end
157
+
147
158
  context "when unexpected keys are allowed" do
148
159
  let(:expected) { { a: 'b' } }
149
160
  let(:actual) { {a: 'c', d: 'e'} }
@@ -74,5 +74,16 @@ module Pact
74
74
 
75
75
  end
76
76
 
77
+ describe 'unpack_regexps' do
78
+ let(:term) { Term.new(generate: 'some', matcher: /s/) }
79
+ let(:body) { [{a: [{b: term}], c:term, d: 1, e: 'blah'}] }
80
+ let(:expected) { [{:a=>[{:b=>/s/}], :c=>/s/, :d=>1, :e=>"blah"}] }
81
+
82
+ it "returns a structure with the Pact::Terms replaced by their regexps" do
83
+ expect(Term.unpack_regexps(body)).to eq expected
84
+ end
85
+
86
+ end
87
+
77
88
  end
78
89
  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.1.0.rc4
4
+ version: 1.1.0.rc5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-05-01 00:00:00.000000000 Z
16
+ date: 2014-05-05 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: randexp
@@ -545,6 +545,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
545
545
  - - ! '>='
546
546
  - !ruby/object:Gem::Version
547
547
  version: '0'
548
+ segments:
549
+ - 0
550
+ hash: 2010055491474427201
548
551
  required_rubygems_version: !ruby/object:Gem::Requirement
549
552
  none: false
550
553
  requirements: