soaspec 0.0.51 → 0.0.52

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: e5b5fa8cf8849c0d7ad63f02428f7a7c7050e7b0
4
- data.tar.gz: 55a05b486e03cb4d7ccb32f3cbfd14be87cd0f09
3
+ metadata.gz: 4911806fb7e9d447b98f407491c2de192f458440
4
+ data.tar.gz: 4674407c680162fb21d61e0c9d2d61e27fca641f
5
5
  SHA512:
6
- metadata.gz: 497e23505b69ba428131d7f327a69d60d25c0db3127a12c09711cca6d26e48212c10129768c63efca13f29a8222a09e0ed1f9ed7a6980963ab8cf7dc81e55754
7
- data.tar.gz: 9873e4e70251804d46114bc60e84877bb778528cd854cb1062044006681f926903c5de323e15a3ab1bf45ebcd63bda1ae6fd37b4b0f5769cc385104c82c17c3e
6
+ metadata.gz: 179745c8a33ec800887bc6d0ee6e30616a4ba348fa6f461e7e94b58a211a060cd52dfeefe7dbf0833c5270ee642b370a954af8e793467b684323e820f1855ae0
7
+ data.tar.gz: 9bfbe31e1b78028e9a51470be0d43c7b5c0c31e897484bdf9ace7adac1a381f9d5964f20b08e72c6e88df101f212e649b9bd8a1c393cfb17b8cad31cc96fc39e
data/ChangeLog CHANGED
@@ -1,7 +1,11 @@
1
+ Version 0.0.52
2
+ * Enhancements
3
+ * Now have 'attribute' accessor making it easy to access an attribute from a response
4
+
1
5
  Version 0.0.51
2
6
  * Enhancements
3
7
  * Allow for 'default_hash=' method to be used in RestHandler. See 'many_calls_one_method_spec' for example
4
- * Got element accessor working correctly (See soap/hash_spec.rb + 'blz_service' for example)
8
+ * Got 'element' accessor working correctly (See soap/hash_spec.rb + 'blz_service' for example)
5
9
 
6
10
  Version 0.0.50
7
11
  * Enhancements
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.51)
4
+ soaspec (0.0.52)
5
5
  jsonpath
6
6
  rest-client (>= 2.0)
7
7
  rspec (~> 3.0)
@@ -15,7 +15,7 @@ require 'soaspec/exchange_handlers/rest_methods'
15
15
  require 'soaspec/exchange'
16
16
  require 'soaspec/matchers'
17
17
  require 'soaspec/soaspec_shared_examples'
18
- require 'soaspec/hash_methods'
18
+ require 'soaspec/core_ext/hash'
19
19
  require 'soaspec/spec_logger'
20
20
  require 'soaspec/exe_helpers'
21
21
  require 'soaspec/exchange_handlers/rest_handler'
@@ -69,7 +69,7 @@ module Soaspec
69
69
 
70
70
  # Change this through 'mandatory_json_values' method to specify json results that must be present in the response
71
71
  # Will be used in 'success_scenarios' shared examples
72
- # @return [Hash] Hash of 'xpath' => 'expected value' pairs
72
+ # @return [Hash] Hash of 'json/path' => 'expected value' pairs
73
73
  def expected_mandatory_json_values
74
74
  {}
75
75
  end
@@ -60,7 +60,8 @@ module Soaspec
60
60
  end
61
61
  end
62
62
 
63
- # Links a particular path to a meaningful name. This will use the 'value_from_path' method which
63
+ # Links a particular path to a meaningful method that can be accessed from Exchange class.
64
+ # This will use the 'value_from_path' method which
64
65
  # should be implemented by each ExchangeHandler
65
66
  # @param [String, Symbol] name Method name used to access element
66
67
  # @param [String, Symbol] path Path to find object (e.g, XPath, JSONPath)
@@ -70,5 +71,17 @@ module Soaspec
70
71
  end
71
72
  end
72
73
 
74
+ # Links an attribute to a meaningful method that can be accessed from Exchange class.
75
+ # This will use the 'value_from_path' method which
76
+ # should be implemented by each ExchangeHandler
77
+ # @param [String, Symbol] name Method name used to access attribute
78
+ # @param [String, nil, Hash] attribute Attribute name. If not set, this will default to @name
79
+ def attribute(name, attribute = nil)
80
+ attribute_used = attribute ? attribute : name.to_s
81
+ define_method("__custom_path_#{name}") do |response|
82
+ value_from_path(response, 'implicit', attribute: attribute_used)
83
+ end
84
+ end
85
+
73
86
  end
74
87
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  require_relative 'exchange_handler'
3
- require_relative '../hash_methods'
3
+ require_relative '../core_ext/hash'
4
4
  require_relative '../not_found_errors'
5
5
  require_relative 'handler_accessors'
6
6
  require_relative '../interpreter'
@@ -1,6 +1,6 @@
1
1
 
2
2
  require_relative 'exchange_handler'
3
- require_relative '../hash_methods'
3
+ require_relative '../core_ext/hash'
4
4
  require_relative '../not_found_errors'
5
5
  require_relative 'handler_accessors'
6
6
  require_relative '../interpreter'
@@ -141,29 +141,33 @@ module Soaspec
141
141
  # Returns the value at the provided xpath
142
142
  # @param [Savon::Response] response
143
143
  # @param [String] xpath
144
+ # @param [String] attribute Generic attribute to find
144
145
  # @return [String] Value inside element found through Xpath
145
- def xpath_value_for(response: nil, xpath: nil)
146
- raise ArgumentError unless response && xpath
146
+ def xpath_value_for(response: nil, xpath: nil, attribute: nil)
147
+ raise ArgumentError('response and xpath must be passed to method') unless response && xpath
147
148
  result =
148
149
  if Soaspec.strip_namespaces? && !xpath.include?(':')
149
150
  temp_doc = response.doc.dup
150
151
  temp_doc.remove_namespaces!
151
- temp_doc.xpath(xpath).first
152
+ temp_doc.at_xpath(xpath)
152
153
  else
153
- response.xpath(xpath).first
154
+ response.xpath(xpath).first # Note this is Savon's xpath method. Hence Nokogiri 'at_xpath' not used
154
155
  end
155
156
  raise NoElementAtPath, "No value at Xpath '#{xpath}' in XML #{response.doc}" unless result
156
- result.inner_text
157
+ return result.inner_text if attribute.nil?
158
+ result.attributes[attribute].inner_text
157
159
  end
158
160
 
159
161
  # Based on a exchange, return the value at the provided xpath
160
162
  # If the path does not begin with a '/', a '//' is added to it
161
163
  # @param [Savon::Response] response
162
164
  # @param [String] path Xpath
165
+ # @param [String] attribute Generic attribute to find. Will override path
163
166
  # @return [String] Value at Xpath
164
- def value_from_path(response, path)
167
+ def value_from_path(response, path, attribute: nil)
168
+ path = "//*[@#{attribute}]" unless attribute.nil?
165
169
  path = '//' + path if path[0] != '/'
166
- xpath_value_for(response: response, xpath: path)
170
+ xpath_value_for(response: response, xpath: path, attribute: attribute)
167
171
  end
168
172
 
169
173
  # Whether any of the keys of the Body Hash include value
@@ -1,9 +1,7 @@
1
1
 
2
- require_relative 'hash_methods'
2
+ require_relative 'core_ext/hash'
3
3
  require_relative 'not_found_errors'
4
4
 
5
- # TODO: Mathcers are specific to SOAP. Make generic for REST and others by using actual.api_class
6
-
7
5
  # Whether response has any element with the provided value
8
6
  RSpec::Matchers.define :contain_value do |expected|
9
7
  match do |actual|
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.51'
2
+ VERSION = '0.0.52'.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.51
4
+ version: 0.0.52
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-01 00:00:00.000000000 Z
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -167,6 +167,7 @@ files:
167
167
  - exe/soaspec-init
168
168
  - exe/xml_to_yaml_file
169
169
  - lib/soaspec.rb
170
+ - lib/soaspec/core_ext/hash.rb
170
171
  - lib/soaspec/exchange.rb
171
172
  - lib/soaspec/exchange_handlers/exchange_handler.rb
172
173
  - lib/soaspec/exchange_handlers/handler_accessors.rb
@@ -174,7 +175,6 @@ files:
174
175
  - lib/soaspec/exchange_handlers/rest_methods.rb
175
176
  - lib/soaspec/exchange_handlers/soap_handler.rb
176
177
  - lib/soaspec/exe_helpers.rb
177
- - lib/soaspec/hash_methods.rb
178
178
  - lib/soaspec/interpreter.rb
179
179
  - lib/soaspec/matchers.rb
180
180
  - lib/soaspec/not_found_errors.rb