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 +4 -4
- data/ChangeLog +4 -0
- data/Gemfile.lock +1 -1
- data/lib/soaspec/exchange.rb +1 -1
- data/lib/soaspec/exchange_handlers/rest_handler.rb +12 -13
- data/lib/soaspec/exchange_handlers/soap_handler.rb +10 -10
- data/lib/soaspec/matchers.rb +6 -6
- data/lib/soaspec/not_found_errors.rb +2 -2
- data/lib/soaspec/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f81e429ef1b144e0977520e79fd5ae9890bf3a89
|
4
|
+
data.tar.gz: ed934b5fcddfee84837c3dbedfd4b90b424377e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/Gemfile.lock
CHANGED
data/lib/soaspec/exchange.rb
CHANGED
@@ -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(
|
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
|
-
|
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 [
|
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(
|
209
|
-
raise ArgumentError unless
|
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
|
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(
|
230
|
-
|
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(
|
233
|
+
xpath_value_for(response: response, xpath: path)
|
234
234
|
when :json
|
235
235
|
path = '$..' + path if path[0] != '$'
|
236
|
-
matching_values = JsonPath.on(
|
237
|
-
raise
|
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.
|
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 [
|
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(
|
155
|
-
raise ArgumentError unless
|
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 =
|
158
|
+
temp_doc = response.doc
|
159
159
|
temp_doc.remove_namespaces!
|
160
160
|
temp_doc.xpath(xpath).first
|
161
161
|
else
|
162
|
-
|
162
|
+
response.xpath(xpath).first
|
163
163
|
end
|
164
|
-
raise
|
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 [
|
170
|
+
# @param [Savon::Response] response
|
171
171
|
# @param [String] path Xpath
|
172
172
|
# @return [String] Value at Xpath
|
173
|
-
def value_from_path(
|
173
|
+
def value_from_path(response, path)
|
174
174
|
path = '//' + path if path[0] != '/'
|
175
|
-
xpath_value_for(
|
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
|
data/lib/soaspec/matchers.rb
CHANGED
@@ -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 |
|
30
|
+
RSpec::Matchers.define :contain_key do |path|
|
31
31
|
match do |actual|
|
32
|
-
expect(actual
|
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 #{
|
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 :
|
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
|
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 :
|
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')
|
data/lib/soaspec/version.rb
CHANGED