soaspec 0.0.45 → 0.0.46

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: 5c4fe1e31ed200c99604632c3cedf641b493f72f
4
- data.tar.gz: c48fc1bf2c281a6fadc6bd64752c6c86222d6bd1
3
+ metadata.gz: f81e429ef1b144e0977520e79fd5ae9890bf3a89
4
+ data.tar.gz: ed934b5fcddfee84837c3dbedfd4b90b424377e5
5
5
  SHA512:
6
- metadata.gz: cddc01b446e5cafab7caab1e33130ec3d57fc3d42b685fd57db2216b59e25750e09952f4777815e23cce726ebbeaf9340c0918984ff76ac925eea5776c54262d
7
- data.tar.gz: 91e7826c080dd542f9363dd06d89ffdc4bff5ffa612f37a4febc7602d8d8dafdff89d75b0c8791271d6fab558d142cba74766322cbbda8811a0aa333852dcefe
6
+ metadata.gz: a64529f623d73ffe61da1c0d0ed28725d19ee4d26563ff804c24f7ea3c36dba203947a216169b3570d1df8b88a3e97e0e10a3de54e71a568da13caacc935ca34
7
+ data.tar.gz: 0b1f8d43be55b3a7a810a5968894093a8d42bebd0e51d46b25921f787c1f8763cf7afc2bafa3fdea97962678ca6dd52f61737c857ca327fff473999fc1fe355a
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.0.46
2
+ * Enhancements
3
+ * 'include_key?' method use 'value_from_path'. Iterating through Hashes with 'include_key?' wouldn't work as expected with some JSON bodies with my current implementation
4
+
1
5
  Version 0.0.45
2
6
  * Enhancements
3
7
  * No need to use 'name' when creating SoapHandler and RestHandler. Default is ClassName
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.45)
4
+ soaspec (0.0.46)
5
5
  jsonpath
6
6
  rest-client (>= 2.0)
7
7
  rspec (~> 3.0)
@@ -94,7 +94,7 @@ class Exchange
94
94
  # @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
95
95
  # @return [String] Value at path
96
96
  def [](path)
97
- @api_class.value_from_path(self, path)
97
+ @api_class.value_from_path(response, path)
98
98
  end
99
99
 
100
100
  end
@@ -174,7 +174,7 @@ module Soaspec
174
174
 
175
175
  # @return [Boolean] Whether response body contains expected key
176
176
  def include_key?(response, expected)
177
- extract_hash(response).include_key? expected
177
+ value_from_path(response, expected)
178
178
  end
179
179
 
180
180
  # @return [Integer] HTTP Status code for response
@@ -202,12 +202,11 @@ module Soaspec
202
202
  end
203
203
 
204
204
  # Returns the value at the provided xpath
205
- # @param [Exchange] exchange
205
+ # @param [RestClient::Response] response
206
206
  # @param [String] xpath
207
207
  # @return [String] Value inside element found through Xpath
208
- def xpath_value_for(exchange: nil, xpath: nil)
209
- raise ArgumentError unless exchange && xpath
210
- response = exchange.response
208
+ def xpath_value_for(response: nil, xpath: nil)
209
+ raise ArgumentError unless response && xpath
211
210
  raise "Can't perform XPATH if response is not XML" unless Interpreter.response_type_for(response) == :xml
212
211
  result =
213
212
  if Soaspec.strip_namespaces? && !xpath.include?(':')
@@ -217,29 +216,29 @@ module Soaspec
217
216
  else
218
217
  Nokogiri.parse(response.body).xpath(xpath).first
219
218
  end
220
- raise NoElementAtXpath, "No value at Xpath '#{xpath}'" unless result
219
+ raise NoElementAtPath, "No value at Xpath '#{xpath}'" unless result
221
220
  result.inner_text
222
221
  end
223
222
 
224
223
  # Based on a exchange, return the value at the provided xpath
225
224
  # If the path does not begin with a '/', a '//' is added to it
226
225
  # @param [Exchange] exchange
227
- # @param [Object] path Xpath or other path identifying how to find element
226
+ # @param [Object] path Xpath, JSONPath or other path identifying how to find element
228
227
  # @return [String] Value at Xpath
229
- def value_from_path(exchange, path)
230
- case Interpreter.response_type_for(exchange.response)
228
+ def value_from_path(response, path)
229
+ path = path.to_s
230
+ case Interpreter.response_type_for(response)
231
231
  when :xml
232
232
  path = '//' + path if path[0] != '/'
233
- xpath_value_for(exchange: exchange, xpath: path)
233
+ xpath_value_for(response: response, xpath: path)
234
234
  when :json
235
235
  path = '$..' + path if path[0] != '$'
236
- matching_values = JsonPath.on(exchange.response.body, path)
237
- raise NoElementInHash, "Element in #{exchange.response.body} not found with path '#{path}'" if matching_values.empty?
236
+ matching_values = JsonPath.on(response.body, path)
237
+ raise NoElementAtPath, "Element in #{response.body} not found with path '#{path}'" if matching_values.empty?
238
238
  matching_values.first
239
239
  else
240
240
  raise 'Unrecognised response message. Neither xml nor json detected'
241
241
  end
242
-
243
242
  end
244
243
 
245
244
  # Convenience methods for once off usage of a REST request
@@ -119,7 +119,7 @@ module Soaspec
119
119
  when :hash
120
120
  response.body
121
121
  when :raw
122
- response.body.to_xml
122
+ response.xml
123
123
  else
124
124
  response.body
125
125
  end
@@ -148,31 +148,31 @@ module Soaspec
148
148
  end
149
149
 
150
150
  # Returns the value at the provided xpath
151
- # @param [Exchange] exchange
151
+ # @param [Savon::Response] response
152
152
  # @param [String] xpath
153
153
  # @return [String] Value inside element found through Xpath
154
- def xpath_value_for(exchange: nil, xpath: nil)
155
- raise ArgumentError unless exchange && xpath
154
+ def xpath_value_for(response: nil, xpath: nil)
155
+ raise ArgumentError unless response && xpath
156
156
  result =
157
157
  if Soaspec.strip_namespaces? && !xpath.include?(':')
158
- temp_doc = exchange.response.doc
158
+ temp_doc = response.doc
159
159
  temp_doc.remove_namespaces!
160
160
  temp_doc.xpath(xpath).first
161
161
  else
162
- exchange.response.xpath(xpath).first
162
+ response.xpath(xpath).first
163
163
  end
164
- raise NoElementAtXpath, "No value at Xpath '#{xpath}'" unless result
164
+ raise NoElementAtPath, "No value at Xpath '#{xpath}'" unless result
165
165
  result.inner_text
166
166
  end
167
167
 
168
168
  # Based on a exchange, return the value at the provided xpath
169
169
  # If the path does not begin with a '/', a '//' is added to it
170
- # @param [Exchange] exchange
170
+ # @param [Savon::Response] response
171
171
  # @param [String] path Xpath
172
172
  # @return [String] Value at Xpath
173
- def value_from_path(exchange, path)
173
+ def value_from_path(response, path)
174
174
  path = '//' + path if path[0] != '/'
175
- xpath_value_for(exchange: exchange, xpath: path)
175
+ xpath_value_for(response: response, xpath: path)
176
176
  end
177
177
 
178
178
  # Whether any of the keys of the Body Hash include value
@@ -27,20 +27,20 @@ RSpec::Matchers.define :include_in_body do |expected|
27
27
  end
28
28
 
29
29
  # Whether expected element exists in body
30
- RSpec::Matchers.define :contain_key do |expected|
30
+ RSpec::Matchers.define :contain_key do |path|
31
31
  match do |actual|
32
- expect(actual.api_class.include_key?(actual.response, expected)).to be true
32
+ expect(actual).to have_element_at_path path
33
33
  end
34
34
 
35
35
  failure_message do |actual|
36
- "expected that #{actual.api_class.response_body(actual.response, format: :hash)} would contain key #{expected}"
36
+ "expected that #{actual.api_class.response_body(actual.response, format: :hash)} would contain key #{path}"
37
37
  end
38
38
  end
39
39
 
40
40
  # Whether an element exists at expected xpath
41
- RSpec::Matchers.define :have_element_at_xpath do |xpath|
41
+ RSpec::Matchers.define :have_element_at_path do |xpath|
42
42
  match do |exchange|
43
- expect { exchange[xpath] }.to_not raise_error # Error will be raised if XPath returns no value
43
+ expect { exchange[xpath] }.to_not raise_error # Error will be raised if Path returns no value
44
44
  end
45
45
 
46
46
  failure_message do |actual|
@@ -48,7 +48,7 @@ RSpec::Matchers.define :have_element_at_xpath do |xpath|
48
48
  end
49
49
  end
50
50
 
51
- RSpec::Matchers.alias_matcher :have_element_at_path, :have_element_at_xpath
51
+ RSpec::Matchers.alias_matcher :have_element_at_xpath, :have_element_at_path
52
52
 
53
53
  # Whether an element at xpath (defined by key) has value (defined by value).
54
54
  # @param [Hash] expected_hash Xpath => Value pair (e.g. '//xmlns:GetWeatherResult' => 'Data Not Found')
@@ -1,7 +1,7 @@
1
1
 
2
2
  # Raised to represent when there's no element at an Xpath
3
- class NoElementAtXpath < StandardError
4
- def initialize(msg="No element at Xpath found")
3
+ class NoElementAtPath < StandardError
4
+ def initialize(msg="No element at path found")
5
5
  super
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.45'
2
+ VERSION = '0.0.46'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.45
4
+ version: 0.0.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA