pact-support 1.16.5 → 1.16.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e0c625aaae1df3561bcc4931619c302e86e7a095532a796ccbb0d72c25fa1a0
4
- data.tar.gz: 5cecf64f0fcdd42ba68cd87fe117a3de729b96f1cd22ae4f47dcb171f78c0fc0
3
+ metadata.gz: 87344137693fa6e4f3a31d9794ab10a09680cebc96d5caaa62b9191b54643347
4
+ data.tar.gz: 4ee4e677c7d144e5fef6bf93ee568ee9a8f588bd04ba6b13b0c45bc7ddb044b8
5
5
  SHA512:
6
- metadata.gz: dcb61af6781e17f964725fdd44452c3fa63b146bc71240c5a2cff6580d7572da316e41af133d4c9ac814d2a8200a72b250e32333292567718c43fbee88aaf3c0
7
- data.tar.gz: 661cf6909d54987e5e9e63ba38ce2b92ac00c2823853ac178670a204ce80adf96084c9665cf622f7a04ce2e50e7948b755c07ffc0d14e344492908bb033966d8
6
+ metadata.gz: a7d9067f4a4582fc58ed8e74abc6201ec21060701f9baf7e40fcbc4887982aafef05afa1a11534bca492e57253ee37f91a764dd03c81abaa4d62cb90976f178a
7
+ data.tar.gz: 607223093f8ec2b7adb4415d229cfa2a0ed2fa2a74e633ed444d61ac2b9775b7097ea11d8b1dc70873b33249cb44c8f7f86ab42c9bbe1369367b99da7cddc77f
@@ -1,3 +1,11 @@
1
+ <a name="v1.16.6"></a>
2
+ ### v1.16.6 (2021-01-28)
3
+
4
+ #### Bug Fixes
5
+
6
+ * raise Pact::Error not RuntimeError when invalid constructor arguments are supplied to a Pact::Term ([d9fb8ea](/../../commit/d9fb8ea))
7
+ * update active support support for Ruby 3.0 ([6c30d42](/../../commit/6c30d42))
8
+
1
9
  <a name="v1.16.5"></a>
2
10
  ### v1.16.5 (2020-11-25)
3
11
 
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Pact Support
2
2
 
3
- [![Build Status](https://travis-ci.com/pact-foundation/pact-support.svg?branch=master)](https://travis-ci.com/pact-foundation/pact-support)
3
+ ![Build status](https://github.com/pact-foundation/pact-support/workflows/Test/badge.svg)
4
4
 
5
5
  Provides shared code for the Pact gems
@@ -2,22 +2,28 @@
2
2
 
3
3
  module Pact
4
4
  module ActiveSupportSupport
5
-
6
5
  extend self
7
6
 
8
7
  def fix_all_the_things thing
9
- if thing.is_a?(Regexp)
10
- fix_regexp(thing)
11
- elsif thing.is_a?(Array)
12
- thing.each{ | it | fix_all_the_things it }
13
- elsif thing.is_a?(Hash)
14
- thing.values.each{ | it | fix_all_the_things it }
15
- elsif thing.class.name.start_with?("Pact")
16
- thing.instance_variables.collect{ | iv_name | thing.instance_variable_get(iv_name)}.each do | iv |
17
- fix_all_the_things iv
8
+ if defined?(ActiveSupport)
9
+ if thing.is_a?(Regexp)
10
+ fix_regexp(thing)
11
+ elsif thing.is_a?(Array)
12
+ thing.collect{ | it | fix_all_the_things it }
13
+ elsif thing.is_a?(Hash)
14
+ thing.each_with_object({}) { | (k, v), new_hash | new_hash[k] = fix_all_the_things(v) }
15
+ elsif thing.is_a?(Pact::Term)
16
+ # matcher Regexp is fixed in its own as_json method
17
+ thing
18
+ elsif thing.class.name.start_with?("Pact")
19
+ warn_about_regexp(thing)
20
+ thing
21
+ else
22
+ thing
18
23
  end
24
+ else
25
+ thing
19
26
  end
20
- thing
21
27
  end
22
28
 
23
29
  # ActiveSupport JSON overwrites (i.e. TRAMPLES) the json methods of the Regexp class directly
@@ -27,10 +33,7 @@ module Pact
27
33
  # original as_json to the Regexp instances in the ConsumerContract before we write them to the
28
34
  # pact file. If anyone can find a better way, please submit a pull request ASAP!
29
35
  def fix_regexp regexp
30
- def regexp.as_json options = {}
31
- {:json_class => 'Regexp', "o" => self.options, "s" => self.source }
32
- end
33
- regexp
36
+ {:json_class => 'Regexp', "o" => regexp.options, "s" => regexp.source }
34
37
  end
35
38
 
36
39
  # Having Active Support JSON loaded somehow kills the formatting of pretty_generate for objects.
@@ -49,5 +52,14 @@ module Pact
49
52
  json.gsub(/\\u([0-9A-Za-z]{4})/) {|s| [$1.to_i(16)].pack("U")}
50
53
  end
51
54
 
55
+ def warn_about_regexp(thing)
56
+ thing.instance_variables.each do | iv_name |
57
+ iv = thing.instance_variable_get(iv_name)
58
+ if iv.is_a?(Regexp)
59
+ require 'pact/configuration'
60
+ Pact.configuration.error_stream.puts("WARN: Instance variable #{iv_name} for class #{thing.class.name} is a Regexp and isn't been serialized properly. Please raise an issue at https://github.com/pact-foundation/pact-support/issues/new.")
61
+ end
62
+ end
63
+ end
52
64
  end
53
65
  end
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Support
3
- VERSION = "1.16.5"
3
+ VERSION = "1.16.6"
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require 'pact/shared/active_support_support'
2
2
  require 'json/add/regexp'
3
+ require 'pact/errors'
3
4
 
4
5
  module Pact
5
6
  class Term
@@ -25,13 +26,13 @@ module Pact
25
26
  def initialize(attributes = {})
26
27
  @generate = attributes[:generate]
27
28
  @matcher = attributes[:matcher]
28
- raise "Please specify a matcher for the Term" unless @matcher != nil
29
- raise "Please specify a value to generate for the Term" unless @generate != nil
30
- raise "Value to generate \"#{@generate}\" does not match regular expression #{@matcher.inspect}" unless @generate =~ @matcher
29
+ raise Pact::Error.new("Please specify a matcher for the Term") unless @matcher != nil
30
+ raise Pact::Error.new("Please specify a value to generate for the Term") unless @generate != nil
31
+ raise Pact::Error.new("Value to generate \"#{@generate}\" does not match regular expression #{@matcher.inspect}") unless @generate =~ @matcher
31
32
  end
32
33
 
33
34
  def to_hash
34
- { json_class: self.class.name, data: { generate: generate, matcher: fix_regexp(matcher)} }
35
+ { json_class: self.class.name, data: { generate: generate, matcher: fix_regexp(matcher) } }
35
36
  end
36
37
 
37
38
  def as_json(options = {})
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.16.5
4
+ version: 1.16.6
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: 2020-11-25 00:00:00.000000000 Z
15
+ date: 2021-01-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: randexp
@@ -318,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
318
318
  - !ruby/object:Gem::Version
319
319
  version: '0'
320
320
  requirements: []
321
- rubygems_version: 3.1.4
321
+ rubygems_version: 3.2.7
322
322
  signing_key:
323
323
  specification_version: 4
324
324
  summary: Shared code for Pact gems