pact-support 1.10.3 → 1.11.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22c9bd406afc40bd0c83b91c36eb49f142512b15
4
- data.tar.gz: f5f990ba3e1c1b5337283a167346a41411b774c6
3
+ metadata.gz: 81a9d5549b8fae48099843919ad94693490e9eb9
4
+ data.tar.gz: 839c24b776dc088241caac15006827c313009bf0
5
5
  SHA512:
6
- metadata.gz: 7b6cff7af477db0aaba912d79bcfe0293926cffcd77a39b61529decb7e391054a9a2adc1981afe6847b6690d57b464d3e1e8a04c3c82398b53f92d14eb5c659e
7
- data.tar.gz: dba22a097b35198446c77bd03f6f305f751406a471adfb5446574662736c344dd599641505fa9b9a022831563026c311687cef2cfdd70ce816093f0d27105c97
6
+ metadata.gz: 63fb22506c12a51dffbf729ed6b4c652599c581a368b47ad7167bfb2a44761fc26b3ecdcbe4b9f8a7ed7f846b9bd592af510491abce1ece6b167f5066d4d3665
7
+ data.tar.gz: '055840b001e39360ce459fc1243f56b26d0f19d01023cae27bdecc8a2349a12e0457d96e8c42f6134e50b38a854258dad988c6ebc997c90a8cdb05c80dc3d0fb'
@@ -1,3 +1,12 @@
1
+ <a name="v1.11.0"></a>
2
+ ### v1.11.0 (2019-06-18)
3
+
4
+
5
+ #### Features
6
+
7
+ * allow Integers and Floats to be considered equivalent when using type based matching. ([d8a70a1](/../../commit/d8a70a1))
8
+
9
+
1
10
  <a name="v1.10.3"></a>
2
11
  ### v1.10.3 (2019-06-07)
3
12
 
@@ -51,6 +51,7 @@ module Pact
51
51
  attr_accessor :error_stream
52
52
  attr_accessor :output_stream
53
53
  attr_accessor :pactfile_write_order
54
+ attr_accessor :treat_all_number_classes_as_equivalent # when using type based matching
54
55
 
55
56
  def self.default_configuration
56
57
  c = Configuration.new
@@ -61,6 +62,7 @@ module Pact
61
62
  c.output_stream = $stdout
62
63
  c.error_stream = $stderr
63
64
  c.pactfile_write_order = :chronological
65
+ c.treat_all_number_classes_as_equivalent = true
64
66
 
65
67
  c
66
68
  end
@@ -20,23 +20,30 @@ module Pact
20
20
  # maintain backwards compatibility
21
21
 
22
22
  module Matchers
23
-
24
23
  NO_DIFF_AT_INDEX = NoDiffAtIndex.new
25
- DEFAULT_OPTIONS = {allow_unexpected_keys: true, type: false}.freeze
26
24
  NO_DIFF = {}.freeze
25
+ NUMERIC_TYPES = %w[Integer Float Fixnum Bignum BigDecimal].freeze
26
+ DEFAULT_OPTIONS = {
27
+ allow_unexpected_keys: true,
28
+ type: false
29
+ }.freeze
27
30
 
28
31
  extend self
29
32
 
30
33
  def diff expected, actual, opts = {}
31
- calculate_diff(expected, actual, DEFAULT_OPTIONS.merge(opts))
34
+ calculate_diff(expected, actual, DEFAULT_OPTIONS.merge(configurable_options).merge(opts))
32
35
  end
33
36
 
34
37
  def type_diff expected, actual, opts = {}
35
- calculate_diff expected, actual, DEFAULT_OPTIONS.merge(opts).merge(type: true)
38
+ calculate_diff expected, actual, DEFAULT_OPTIONS.merge(configurable_options).merge(opts).merge(type: true)
36
39
  end
37
40
 
38
41
  private
39
42
 
43
+ def configurable_options
44
+ { treat_all_number_classes_as_equivalent: Pact.configuration.treat_all_number_classes_as_equivalent }
45
+ end
46
+
40
47
  def calculate_diff expected, actual, opts = {}
41
48
  options = DEFAULT_OPTIONS.merge(opts)
42
49
  case expected
@@ -156,22 +163,22 @@ module Pact
156
163
 
157
164
  def object_diff expected, actual, options
158
165
  if options[:type]
159
- type_difference expected, actual
166
+ type_difference expected, actual, options
160
167
  else
161
168
  exact_value_diff expected, actual, options
162
169
  end
163
170
  end
164
171
 
165
172
  def exact_value_diff expected, actual, options
166
- if expected != actual
167
- Difference.new expected, actual, value_difference_message(expected, actual, options)
168
- else
173
+ if expected == actual
169
174
  NO_DIFF
175
+ else
176
+ Difference.new expected, actual, value_difference_message(expected, actual, options)
170
177
  end
171
178
  end
172
179
 
173
- def type_difference expected, actual
174
- if types_match? expected, actual
180
+ def type_difference expected, actual, options
181
+ if types_match? expected, actual, options
175
182
  NO_DIFF
176
183
  else
177
184
  TypeDifference.new type_diff_expected_display(expected), type_diff_actual_display(actual), type_difference_message(expected, actual)
@@ -186,8 +193,16 @@ module Pact
186
193
  actual.is_a?(KeyNotFound) ? actual : ActualType.new(actual)
187
194
  end
188
195
 
189
- def types_match? expected, actual
190
- expected.class == actual.class || (is_boolean(expected) && is_boolean(actual))
196
+ # Make options optional to support existing monkey patches
197
+ def types_match? expected, actual, options = {}
198
+ expected.class == actual.class ||
199
+ (is_boolean(expected) && is_boolean(actual)) ||
200
+ (options.fetch(:treat_all_number_classes_as_equivalent, false) && is_number?(expected) && is_number?(actual))
201
+ end
202
+
203
+ def is_number? object
204
+ # deal with Fixnum and Integer without warnings by using string class names
205
+ NUMERIC_TYPES.include?(object.class.to_s)
191
206
  end
192
207
 
193
208
  def is_boolean object
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Support
3
- VERSION = "1.10.3"
3
+ VERSION = "1.11.0"
4
4
  end
5
5
  end
@@ -32,13 +32,14 @@ module Pact::Matchers
32
32
  [INT, 2, "Expected 1 but got 2 at <path>"],
33
33
  [INT, nil, "Expected 1 but got nil at <path>"],
34
34
  [INT, STRING, "Expected 1 but got \"foo\" at <path>"],
35
- [INT, FLOAT, "Expected 1 but got \"foo\" at <path>", {pending: true}],
35
+ [INT, FLOAT, nil],
36
36
  [INT, HASH, "Expected 1 but got a Hash at <path>"],
37
37
  [INT, ARRAY, "Expected 1 but got an Array at <path>"],
38
38
  [Pact.like(INT), 2, nil],
39
39
  [Pact.like(INT), nil, "Expected #{a_numeric} (like 1) but got nil at <path>"],
40
40
  [Pact.like(INT), STRING, "Expected #{a_numeric} (like 1) but got a String (\"foo\") at <path>"],
41
- [Pact.like(INT), FLOAT, "Expected #{a_numeric} (like 1) but got a Float (1.0) at <path>"],
41
+ [Pact.like(INT), FLOAT, "Expected #{a_numeric} (like 1) but got a Float (1.0) at <path>", { treat_all_number_classes_as_equivalent: false }],
42
+ [Pact.like(INT), FLOAT, nil, { treat_all_number_classes_as_equivalent: true }],
42
43
  [Pact.like(INT), HASH, "Expected #{a_numeric} (like 1) but got a Hash at <path>"],
43
44
  [Pact.like(INT), ARRAY, "Expected #{a_numeric} (like 1) but got an Array at <path>"],
44
45
  [HASH, HASH, nil],
@@ -56,9 +57,9 @@ module Pact::Matchers
56
57
  [ARRAY, HASH, "Expected an Array but got a Hash at <path>"]
57
58
  ]
58
59
 
59
- COMBINATIONS.each do | expected, actual, expected_message, options |
60
- context "when expected is #{expected.inspect} and actual is #{actual.inspect}", options || {} do
61
- let(:difference) { diff({thing: expected}, {thing: actual}) }
60
+ COMBINATIONS.each do | expected, actual, expected_message, diff_options |
61
+ context "when expected is #{expected.inspect} and actual is #{actual.inspect}" do
62
+ let(:difference) { diff({thing: expected}, {thing: actual}, diff_options || {}) }
62
63
  let(:message) { difference[:thing] ? difference[:thing].message : nil }
63
64
 
64
65
  it "returns the message '#{expected_message}'" do
@@ -30,19 +30,60 @@ module Pact::Matchers
30
30
  end
31
31
 
32
32
  context "when the headers do not match" do
33
-
34
33
  let(:actual) { Pact::Headers.new('Content-Length' => '1')}
35
34
  let(:difference) { {"Content-Type" => Difference.new('application/hippo', Pact::KeyNotFound.new)} }
36
35
  it "returns a diff" do
37
36
  expect(diff(expected, actual)).to eq difference
38
37
  end
38
+ end
39
+ end
40
+
41
+
42
+ context 'when treat_all_number_classes_as_equivalent is true' do
43
+ let(:options) { { treat_all_number_classes_as_equivalent: true } }
44
+
45
+ describe 'matching numbers with something like' do
46
+ let(:expected) { Pact::SomethingLike.new( { a: 1.1 } ) }
47
+ let(:actual) { { a: 2 } }
39
48
 
49
+ it 'returns an empty diff' do
50
+ expect(diff(expected, actual, options)).to eq({})
51
+ end
40
52
  end
41
53
 
54
+ describe 'with exact matching' do
55
+ let(:expected) { { a: 1 } }
56
+ let(:actual) { { a: 1.0 } }
57
+
58
+ it 'returns an empty diff' do
59
+ expect(diff(expected, actual, options)).to eq({})
60
+ end
61
+ end
42
62
  end
43
63
 
44
- describe 'matching with something like' do
64
+ context 'when treat_all_number_classes_as_equivalent is false' do
65
+ let(:options) { { treat_all_number_classes_as_equivalent: false } }
45
66
 
67
+ describe 'matching numbers with something like' do
68
+ let(:expected) { Pact::SomethingLike.new( { a: 1.1 } ) }
69
+ let(:actual) { { a: 2 } }
70
+
71
+ it 'returns a diff' do
72
+ expect(diff(expected, actual, options)).to_not eq({})
73
+ end
74
+ end
75
+
76
+ describe 'with exact matching' do
77
+ let(:expected) { { a: 1 } }
78
+ let(:actual) { { a: 1.0 } }
79
+
80
+ it 'returns an empty diff because in Ruby 1.0 == 1' do
81
+ expect(diff(expected, actual)).to eq({})
82
+ end
83
+ end
84
+ end
85
+
86
+ describe 'matching with something like' do
46
87
  context 'when the actual is something like the expected' do
47
88
  let(:expected) { Pact::SomethingLike.new( { a: 1 } ) }
48
89
  let(:actual) { { a: 2 } }
@@ -50,7 +91,6 @@ module Pact::Matchers
50
91
  it 'returns an empty diff' do
51
92
  expect(diff(expected, actual)).to eq({})
52
93
  end
53
-
54
94
  end
55
95
 
56
96
  context 'when the there is a mismatch of a parent, and a child contains a SomethingLike' do
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: 1.10.3
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2019-06-06 00:00:00.000000000 Z
15
+ date: 2019-06-18 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: randexp