soaspec 0.0.72 → 0.0.73

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: a9bd5b574f650987fe784eaeed4d9733e40cbd03
4
- data.tar.gz: c9ab8b52fe53aa3b8ebc3807af2a0253906eceec
3
+ metadata.gz: 560cab022af5b3297cf79ae3bfd3b71cb023ac3d
4
+ data.tar.gz: c178b241de61f0ff91001ab1c710dd196ec6e611
5
5
  SHA512:
6
- metadata.gz: a6b62377f9886cded11a729200f801c110ded422c31139c4dad350203b9404c01e4ade7e0c3a6fc9052a800ae0f2fa6341831e44e0f2a569954ad94354100de7
7
- data.tar.gz: 24426a3ba9435bcf73c048d955be8fea9e2e23ccf0741ef442499d900ef46bb76c0b82f11fa5f8fbc9e1351e23a43efb3dfbb473b2bd8f79ed73b7667be9a179
6
+ metadata.gz: 4aad8d63361904d563c10534248dc90376d493712e579e6da2d1e8a787940664e51261531bcd2d37e038c28bfe19e300665f9df3a65b7c5841a968246ec9fcd7
7
+ data.tar.gz: 0e93c0c83266d50026b4c36488b63abbe26a31987006fa2f964487b9c94d3c74517c26c228ba0a927c3840716e4f2b9ace495ac6bb8d8bd3e7e3d36a6495c16b
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ Version 0.0.73
2
+ * Enhancements
3
+ * Added 'default_handler' method with which define an exchange_handler to be created when an exchange is initialized
4
+ * Refactoring
5
+ * Use `@exchange_handler` instead of `@api_class` which is more consistent
6
+
1
7
  Version 0.0.72
2
8
  * Enhancements
3
9
  * Add ability to convert XML response to lower case for simpler xpath searching
@@ -1,10 +1,26 @@
1
1
  require_relative '../soaspec'
2
2
 
3
+ # Convenience methods to set Exchange specific properties
4
+ module ExchangeAccessors
5
+
6
+ # Set default exchange handler for this exchange
7
+ # This is helpful for when you need a new exchange handler created for each exchange
8
+ def default_handler(handler_class, name = handler_class.to_s, params = {})
9
+ define_method('default_handler_used') do
10
+ handler_class.new name, params
11
+ end
12
+ end
13
+ end
14
+
3
15
  # This represents a request / response pair
16
+ # Essentially, params in the exchange that are set are related to the request
17
+ # What is returned is related to the response
4
18
  class Exchange
5
19
 
6
- # Class of Api Handler for which this exchange is made
7
- attr_accessor :api_class
20
+ extend ExchangeAccessors
21
+
22
+ # Class of Exchange Handler for which this exchange is made
23
+ attr_accessor :exchange_handler
8
24
  # How many times to retry for a success
9
25
  attr_accessor :retry_count
10
26
  # Name used for displaying class
@@ -22,28 +38,38 @@ class Exchange
22
38
  @retry_for_success
23
39
  end
24
40
 
41
+ # @return [Boolean] Soaspec::ExchangeHandler used by this exchange
42
+ def default_handler_used
43
+ nil
44
+ end
45
+
46
+ # @param [String] element Element to define methods for
47
+ def methods_for_element(element)
48
+ element_name = element.to_s.split('__custom_path_').last
49
+ define_singleton_method(element_name) do
50
+ exchange_handler.__send__(element, response) # Forward the call onto handler to retrieve the element for the response
51
+ end
52
+ define_singleton_method("#{element_name}?") do
53
+ begin
54
+ __send__ element_name
55
+ true
56
+ rescue NoElementAtPath
57
+ false
58
+ end
59
+ end
60
+ end
61
+
25
62
  # @param [Symbol, String] name Name shown in RSpec run
26
63
  # @param [Hash] override_parameters Parameters to override for default params
27
64
  def initialize(name = self.class.to_s, override_parameters = {})
28
65
  self.test_name ||= name.to_s
29
- @api_class ||= Soaspec.api_handler # This uses the global parameter. The handler should be set straight before an exchange is made
66
+ # As a last resort this uses the global parameter. The handler should be set straight before an exchange is made to use this
67
+ @exchange_handler ||= default_handler_used || Soaspec.api_handler
68
+ raise '@exchange_handler not set. Set either with `Soaspec.api_handler = Handler.new` or within the exchange' unless @exchange_handler
30
69
  @override_parameters = override_parameters
31
70
  @retry_for_success = false
32
71
  self.retry_count = 3
33
- @api_class.elements.each do |element|
34
- element_name = element.to_s.split('__custom_path_').last
35
- define_singleton_method(element_name) do
36
- @api_class.__send__(element, response) # Forward the call onto handler to retrieve the element for the response
37
- end
38
- define_singleton_method("#{element_name}?") do
39
- begin
40
- __send__ element_name
41
- true
42
- rescue NoElementAtPath
43
- false
44
- end
45
- end
46
- end
72
+ @exchange_handler.elements.each { |element| methods_for_element(element) }
47
73
  end
48
74
 
49
75
  # Specify a url to add onto the base_url of the ExchangeHandler used
@@ -65,9 +91,9 @@ class Exchange
65
91
  Soaspec::SpecLogger.add_to 'Example ' + test_name
66
92
  request_params = @override_parameters
67
93
  retry_count.times do
68
- response = @api_class.make_request(request_params)
94
+ response = @exchange_handler.make_request(request_params)
69
95
  return response unless retry_for_success?
70
- return response if (200..299).cover? @api_class.status_code_for(response)
96
+ return response if (200..299).cover? @exchange_handler.status_code_for(response)
71
97
  response
72
98
  end
73
99
  end
@@ -76,7 +102,7 @@ class Exchange
76
102
  # @param [Symbol] name Name of method to use to access this value within handler
77
103
  # @param [String] value Path to value to store
78
104
  def store(name, value)
79
- @api_class.store(name, self[value])
105
+ @exchange_handler.store(name, self[value])
80
106
  end
81
107
 
82
108
  # Retrieve the stored value from the Api Handler
@@ -84,8 +110,8 @@ class Exchange
84
110
  # @return [Object] value from the Api Handler stored previously
85
111
  def retrieve(name)
86
112
  method = '__stored_val__' + name.to_s
87
- raise ArgumentError('Value not stored at ') unless api_class.respond_to? method
88
- @api_class.send(method)
113
+ raise ArgumentError('Value not stored at ') unless exchange_handler.respond_to? method
114
+ exchange_handler.send(method)
89
115
  end
90
116
 
91
117
  # Name describing this class when used with `RSpec.describe`
@@ -108,7 +134,7 @@ class Exchange
108
134
  # Get status code from api class. This is http response for Web Api
109
135
  # @return [Integer] Status code from api class
110
136
  def status_code
111
- @api_class.status_code_for(response)
137
+ @exchange_handler.status_code_for(response)
112
138
  end
113
139
 
114
140
  # Dummy request used to make a request without verifying it and ignoring WSDL errors
@@ -134,7 +160,7 @@ class Exchange
134
160
  # @param [Object] path Path to return element for api class E.g - for SOAP this is XPath string. For JSON, this is Hash dig Array
135
161
  # @return [String] Value at path
136
162
  def [](path)
137
- @api_class.value_from_path(response, path.to_s)
163
+ @exchange_handler.value_from_path(response, path.to_s)
138
164
  end
139
165
 
140
166
  # Set a parameter request in the request body.
@@ -5,22 +5,22 @@ require_relative 'not_found_errors'
5
5
  # Whether response has any element with the provided value
6
6
  RSpec::Matchers.define :contain_value do |expected|
7
7
  match do |actual|
8
- expect(actual.api_class.include_value?(actual.response, expected)).to be true
8
+ expect(actual.exchange_handler.include_value?(actual.response, expected)).to be true
9
9
  end
10
10
 
11
11
  failure_message do |actual|
12
- "expected that #{actual.api_class.response_body(actual.response, format: :hash)} would contain value #{expected}"
12
+ "expected that #{actual.exchange_handler.response_body(actual.response, format: :hash)} would contain value #{expected}"
13
13
  end
14
14
  end
15
15
 
16
16
  # Whether substring exists in body of response (more general than above)
17
17
  RSpec::Matchers.define :include_in_body do |expected|
18
18
  match do |actual|
19
- expect(actual.api_class.include_in_body?(actual.response, expected)).to be true
19
+ expect(actual.exchange_handler.include_in_body?(actual.response, expected)).to be true
20
20
  end
21
21
 
22
22
  failure_message do |actual|
23
- "expected that #{actual.api_class.response_body(actual.response, format: :raw)} would contain value #{expected}"
23
+ "expected that #{actual.exchange_handler.response_body(actual.response, format: :raw)} would contain value #{expected}"
24
24
  end
25
25
  end
26
26
 
@@ -32,7 +32,7 @@ RSpec::Matchers.define :have_element_at_path do |xpath|
32
32
 
33
33
  # TODO: Would be better to print failure message
34
34
  failure_message do |actual|
35
- "expected that #{actual.api_class.response_body(actual.response, format: :raw)} would have element at path '#{xpath}'"
35
+ "expected that #{actual.exchange_handler.response_body(actual.response, format: :raw)} would have element at path '#{xpath}'"
36
36
  end
37
37
  end
38
38
 
@@ -56,7 +56,7 @@ end
56
56
  RSpec::Matchers.define :be_found do
57
57
 
58
58
  match do |exchange|
59
- expect(exchange.api_class.found?(exchange.response)).to be true
59
+ expect(exchange.exchange_handler.found?(exchange.response)).to be true
60
60
  end
61
61
 
62
62
  failure_message do |exchange|
@@ -5,18 +5,18 @@ shared_examples_for 'success scenario' do
5
5
  expect(200..299).to cover described_class.status_code
6
6
  end
7
7
  context 'has expected mandatory elements' do
8
- described_class.api_class.expected_mandatory_elements.each do |mandatory_element|
8
+ described_class.exchange_handler.expected_mandatory_elements.each do |mandatory_element|
9
9
  it mandatory_element do
10
10
  expect(described_class).to contain_key mandatory_element
11
11
  end
12
12
  end
13
13
  end
14
- described_class.api_class.expected_mandatory_xpath_values.each do |xpath, value|
14
+ described_class.exchange_handler.expected_mandatory_xpath_values.each do |xpath, value|
15
15
  it "has xpath '#{xpath}' equal to '#{value}'" do
16
16
  expect(described_class).to have_xpath_value(xpath => value)
17
17
  end
18
18
  end
19
- described_class.api_class.expected_mandatory_json_values.each do |xpath, value|
19
+ described_class.exchange_handler.expected_mandatory_json_values.each do |xpath, value|
20
20
  it "has xpath '#{xpath}' equal to '#{value}'" do
21
21
  expect(described_class).to have_xpath_value(xpath => value)
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.72'.freeze
2
+ VERSION = '0.0.73'.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.0.72
4
+ version: 0.0.73
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-06 00:00:00.000000000 Z
11
+ date: 2018-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler