soaspec 0.2.3 → 0.2.4

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: 757cc34fa056aa23860299c614c1e981b96a6c7d
4
- data.tar.gz: af77364e1117ea4fc27d7375ab9366c6d6f3d222
3
+ metadata.gz: 6fc08897eb83281f6c6226c6f0df1768129ec307
4
+ data.tar.gz: 58e5b2672c36a667471f97159e63dea73ca44dbe
5
5
  SHA512:
6
- metadata.gz: aabc608e6182a76290d7c546f66f722dd19c4d7b183f263cffd7bcc3f569951c15c9beb2925a455d7e4c71dcb0d6990ebd4919535f1026b6422cae05f49c364e
7
- data.tar.gz: 51547871679bbbd4c23c261315f241980f417c9c4bcd1802f450a801c60b2e4abf712c49bcb12c14a692314997377b6c7e2bb18f843194e677d965cc59c39d2f
6
+ metadata.gz: 603ad5943c9f9e063163ab0cf485af270f0a91639a0c7a4535a9e2aeae757fac9d9ad442b14d039ece23316827e3be39ee3c53532a1cdc148d6526b37e9adc1b
7
+ data.tar.gz: 03312d09ccada29afa1c5d61a8a1a559287cdd35f96289b53490f25f22d3d07e44368e14824bfdd8ef5dce579de0f4ec2d64e7a76dadc8dfc50cfdfc1bf823d0
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.2.4
2
+ * Enhancements
3
+ * Enable block to be used when creating exchange with Handler.exchange
4
+
1
5
  Version 0.2.3
2
6
  * Enhancements
3
7
  * Exchange.until itself method returns itself making it easier to reuse last result in assertions
@@ -12,7 +12,7 @@ module Soaspec
12
12
  # @option override_parameters [String] :template_name Path to file to be read via ERB and passed in request body
13
13
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
14
14
  def post(params = {})
15
- # This is a stub, used for indexing, source code below
15
+ perform_exchange_with(:post, params)
16
16
  end
17
17
 
18
18
  # Make REST Exchange with 'patch' method within this Handler context
@@ -26,7 +26,7 @@ module Soaspec
26
26
  # @option override_parameters [String] :template_name Path to file to be read via ERB and passed in request body
27
27
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
28
28
  def patch(params)
29
- # This is a stub, used for indexing, source code below
29
+ perform_exchange_with(:patch, params)
30
30
  end
31
31
 
32
32
  # Make REST Exchange with 'put' method within this Handler context
@@ -40,7 +40,7 @@ module Soaspec
40
40
  # @option override_parameters [String] :template_name Path to file to be read via ERB and passed in request body
41
41
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
42
42
  def put(params = {})
43
- # This is a stub, used for indexing, source code below
43
+ perform_exchange_with(:put, params)
44
44
  end
45
45
 
46
46
  # Make REST Exchange with 'get' method within this Handler context.
@@ -55,7 +55,7 @@ module Soaspec
55
55
  # @option override_parameters [String] :template_name Path to file to be read via ERB and passed in request body
56
56
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
57
57
  def get(params = {})
58
- # This is a stub, used for indexing, source code below
58
+ perform_exchange_with(:get, params)
59
59
  end
60
60
 
61
61
  # Make REST Exchange with 'delete' method within this Handler context.
@@ -70,34 +70,42 @@ module Soaspec
70
70
  # @option override_parameters [String] :template_name Path to file to be read via ERB and passed in request body
71
71
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
72
72
  def delete(params = {})
73
- # This is a stub, used for indexing, source code below
73
+ perform_exchange_with(:delete, params)
74
74
  end
75
75
 
76
- methods = %w[post patch put get delete]
76
+ private
77
77
 
78
- methods.each do |rest_method|
79
- # Make REST Exchange within this Handler context
80
- # @param [Hash, String] params Exchange parameters.
81
- # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
82
- define_method(rest_method) do |params = {}|
83
- unless params.is_a? Hash
84
- params = case rest_method
85
- when 'get', 'delete'
86
- { suburl: params.to_s }
87
- when 'post', 'put', 'patch'
88
- { payload: params.to_s }
89
- else
90
- raise "'#{params}' needs to be a 'Hash' but is a #{params.class}"
91
- end
92
- end
93
- params[:name] ||= rest_method
94
- exchange_params = { name: params[:name] }
95
- if params[:template_name]
96
- exchange_params[:template_name] = params[:template_name]
97
- params.delete :template_name
98
- end
99
- new(exchange_params)
100
- Exchange.new(params[:name], method: rest_method.to_sym, **params)
78
+ # Make REST Exchange within this Handler context
79
+ # @param [Symbol] rest_method HTTP rest method to use
80
+ # @param [Hash, String] params Exchange parameters.
81
+ # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
82
+ def perform_exchange_with(rest_method, params = {})
83
+ params = determine_params_for(rest_method, params)
84
+ params[:name] ||= rest_method.to_s
85
+ exchange_params = { name: params[:name] }
86
+ if params[:template_name]
87
+ exchange_params[:template_name] = params[:template_name]
88
+ params.delete :template_name
89
+ end
90
+ new(exchange_params)
91
+ exchange = Exchange.new(params[:name], method: rest_method, **params)
92
+ yield exchange if block_given?
93
+ exchange
94
+ end
95
+
96
+ # @param [Symbol] method HTTP rest method to use
97
+ # @param [Hash, String] params Exchange parameters.
98
+ # @return [Hash] Exchange Parameters after setting shorthand parameters
99
+ def determine_params_for(method, params)
100
+ return params if params.is_a? Hash
101
+
102
+ case method
103
+ when :get, :delete
104
+ { suburl: params.to_s }
105
+ when :post, :put, :patch
106
+ { payload: params.to_s }
107
+ else
108
+ raise "'#{params}' needs to be a 'Hash' but is a #{params.class}"
101
109
  end
102
110
  end
103
111
  end
@@ -218,6 +218,7 @@ module Soaspec
218
218
  tmp_class.operation = method_name
219
219
  exchange = Exchange.new(method_name, *args)
220
220
  exchange.exchange_handler = tmp_class
221
+ yield exchange if block_given?
221
222
  exchange
222
223
  else
223
224
  super
@@ -26,7 +26,9 @@ end
26
26
 
27
27
  # Whether an element exists at expected xpath
28
28
  RSpec::Matchers.define :have_element_at_path do |xpath|
29
- match do |exchange|
29
+ match do |object|
30
+ # Object like `response` returns the Exchange object from which a path can be obtained
31
+ exchange = object.respond_to?(:exchange) ? object.exchange : object
30
32
  expect { exchange[xpath] }.to_not raise_error # Error will be raised if Path returns no value
31
33
  end
32
34
 
@@ -42,7 +44,9 @@ RSpec::Matchers.alias_matcher :contain_key, :have_element_at_path
42
44
  # Whether an element at xpath (defined by key) has value (defined by value).
43
45
  # @param [Hash] expected_hash Xpath => Value pair (e.g. '//xmlns:GetWeatherResult' => 'Data Not Found')
44
46
  RSpec::Matchers.define :have_xpath_value do |expected_hash|
45
- match do |exchange|
47
+ match do |object|
48
+ # Object like `response` returns the Exchange object from which a path can be obtained
49
+ exchange = object.respond_to?(:exchange) ? object.exchange : object
46
50
  expected_hash = Hash[*expected_hash.flatten] if expected_hash.is_a?(Array) # For some reason Array was occuring
47
51
  expect(exchange[expected_hash.keys.first]).to eq expected_hash.values.first
48
52
  end
@@ -50,9 +54,10 @@ RSpec::Matchers.define :have_xpath_value do |expected_hash|
50
54
  failure_message do |actual|
51
55
  "expected that xpath '#{expected_hash.keys.first}' has value '#{expected_hash.values.first}' but was '#{actual[expected_hash.keys.first]}'"
52
56
  end
53
-
54
57
  end
55
58
 
59
+ RSpec::Matchers.alias_matcher :have_jsonpath_value, :have_xpath_value
60
+
56
61
  RSpec::Matchers.define :be_found do
57
62
 
58
63
  match do |exchange|
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.2.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-29 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler