pact-message 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: 4623b490060cc82d7c1349fd6119c7eb9db846be
4
- data.tar.gz: 0b65825c719cb6112732fbef9ae4a7d970ff09b0
3
+ metadata.gz: eb08c5946bc8332b709fbe150f0a1bac91dd48ad
4
+ data.tar.gz: 4fe6956ee6a15e093e74f2970b953ab4cedaa671
5
5
  SHA512:
6
- metadata.gz: 2410094b111d55139aa5d7680df0c17be09b2ac4977f155a202b57c96119d45656cfd558593817c577c3e4931f522316b8a65862843ed7da7dcf97869aff252d
7
- data.tar.gz: d8c0cf553285955e4746b64e8703893e6870e09e094e8189f74fa95214dfe80b618fe94dde211e83ba74875768eb27981c43f7bf02d5aa19dfab7dd6c2f675fe
6
+ metadata.gz: 5f2b71dea1efceef4f09cd8c89e12ca9f86e18fb4b1ae43dfe93b11cb43a447055fc732ff8baf17a1a01962748f6ebcb1108b3327c4e0d7caffbc5d220eedde9
7
+ data.tar.gz: 8d141b680689853b612c6052bb2821d711f5f1b6b5fdde4ac6426427d18dd632f8c55121c7644aec074cb7ffb82657b8ddcff491c6e2d8bd87abb785478dfbdd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ <a name="v0.4.0"></a>
2
+ ### v0.4.0 (2018-04-03)
3
+
4
+
5
+ #### Features
6
+
7
+ * add *partial* support for reading/writing array of provider states as specified in v3 spec ([e9ec6c3](/../../commit/e9ec6c3))
8
+
9
+
1
10
  <a name="v0.3.0"></a>
2
11
  ### v0.3.0 (2018-04-03)
3
12
 
@@ -22,6 +22,10 @@ module Pact
22
22
  end
23
23
  end
24
24
 
25
+ def content
26
+ @content
27
+ end
28
+
25
29
  def as_json
26
30
  @content
27
31
  end
@@ -28,7 +28,10 @@ module Pact
28
28
  end
29
29
  content_hash = Pact::MatchingRules.merge(hash['content'], hash['content']['matchingRules'], opts)
30
30
  content = Pact::ConsumerContract::Message::Content.from_hash(content_hash)
31
- new(symbolize_keys(hash).merge(content: content))
31
+ provider_state = hash['providerStates'] && hash['providerStates'].first && hash['providerStates'].first['name']
32
+ warn_if_multiple_provider_states(provider_state, hash)
33
+ warn_if_params_used_in_provider_states(hash)
34
+ new(symbolize_keys(hash).merge(content: content, provider_state: provider_state))
32
35
  end
33
36
 
34
37
  def to_hash
@@ -114,6 +117,24 @@ module Pact
114
117
  def to_s
115
118
  to_hash.to_s
116
119
  end
120
+
121
+ private
122
+
123
+ def self.warn_if_multiple_provider_states(provider_state, hash)
124
+ if hash['providerStates'] && hash['providerStates'].size > 1
125
+ ignored_list = hash['providerStates'].collect{ |provider_state| "\"#{provider_state['name']}\"" }[1..-1].join(", ")
126
+ Pact.configuration.error_stream.puts("WARN: Using only the first provider state, \"#{provider_state}\", as support for multiple provider states is not yet implemented. Ignoring provider states: #{ignored_list}")
127
+ end
128
+ end
129
+
130
+ def self.warn_if_params_used_in_provider_states(hash)
131
+ return unless hash['providerStates']
132
+ provider_states_with_params = hash['providerStates'].select{ | provider_state | provider_state.fetch('params', {}).any? }
133
+ if provider_states_with_params.any?
134
+ ignored_list = provider_states_with_params.collect{ |provider_state| "\"#{provider_state['name']}\"" }.join(", ")
135
+ Pact.configuration.error_stream.puts("WARN: Ignoring params for the following provider states as params support is not yet implemented: #{ignored_list}")
136
+ end
137
+ end
117
138
  end
118
139
  end
119
140
  end
@@ -14,7 +14,7 @@ module Pact
14
14
  require 'pact/message'
15
15
  require 'pact/message/consumer/update_pact'
16
16
  pact_specification_version = Pact::SpecificationVersion.new(options.pact_specification_version)
17
- message = Pact::Message.from_hash(JSON.parse(message), { pact_specification_version: pact_specification_version })
17
+ message = Pact::Message.from_hash(JSON.load(message), { pact_specification_version: pact_specification_version })
18
18
  Pact::Message::Consumer::UpdatePact.call(message, options.pact_dir, options.consumer, options.provider, options.pact_specification_version)
19
19
  end
20
20
 
@@ -7,15 +7,16 @@ module Pact
7
7
 
8
8
  include ActiveSupportSupport
9
9
 
10
- def initialize interaction, decorator_options = {}
11
- @interaction = interaction
10
+ def initialize message, decorator_options = {}
11
+ @message = message
12
12
  @decorator_options = decorator_options
13
13
  end
14
14
 
15
15
  def as_json options = {}
16
- hash = { :description => interaction.description }
17
- hash[:providerState] = interaction.provider_state if interaction.provider_state
18
- hash[:content] = decorate_content
16
+ hash = { :description => message.description }
17
+ hash[:providerStates] = provider_states if message.provider_state
18
+ hash[:content] = extract_content
19
+ hash[:matchingRules] = extract_matching_rules
19
20
  fix_all_the_things hash
20
21
  end
21
22
 
@@ -25,10 +26,28 @@ module Pact
25
26
 
26
27
  private
27
28
 
28
- attr_reader :interaction
29
+ attr_reader :message
29
30
 
30
31
  def decorate_content
31
- interaction.content.as_json
32
+ message.content.as_json
33
+ end
34
+
35
+ def extract_content
36
+ Pact::Reification.from_term(message.content.content)
37
+ end
38
+
39
+ def provider_states
40
+ [{ name: message.provider_state }]
41
+ end
42
+
43
+ def extract_matching_rules
44
+ {
45
+ body: Pact::MatchingRules.extract(message.content.content, pact_specification_version: pact_specification_version)
46
+ }
47
+ end
48
+
49
+ def pact_specification_version
50
+ Pact::SpecificationVersion.new(@decorator_options[:pact_specification_version])
32
51
  end
33
52
  end
34
53
  end
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Message
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/pact-message.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
- spec.add_runtime_dependency "pact-support", "~> 1.5"
32
+ spec.add_runtime_dependency "pact-support", "~> 1.6"
33
33
  # pact-mock_service dependencies are Pact::ConsumerContractDecorator
34
34
  # and Pact::ConsumerContractWriter. Potentially we should extract
35
35
  # or duplicate these classes to remove the pact-mock_service dependency.
@@ -0,0 +1,10 @@
1
+ bundle exec bin/pact-message update '{
2
+ "description": "a test mesage",
3
+ "content": {
4
+ "name": {
5
+ "contents": "Mary",
6
+ "json_class": "Pact::SomethingLike"
7
+ }
8
+ }
9
+ }
10
+ ' --consumer Foo --provider Bar --pact-dir ./tmp --pact-specification-version 3.0.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact-message
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '1.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pact-mock_service
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -182,6 +182,7 @@ files:
182
182
  - lib/pact/message/version.rb
183
183
  - pact-message.gemspec
184
184
  - script/release.sh
185
+ - script/update-pact.sh
185
186
  - tasks/release.rake
186
187
  homepage: http://pact.io
187
188
  licenses: