soaspec 0.0.22 → 0.0.23
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 +4 -4
- data/.rubocop.yml +2 -0
- data/ChangeLog +4 -0
- data/Gemfile.lock +1 -1
- data/exe/soaspec-generate +0 -0
- data/lib/soaspec.rb +1 -0
- data/lib/soaspec/basic_soap_handler.rb +4 -1
- data/lib/soaspec/matchers.rb +12 -2
- data/lib/soaspec/rest_handler.rb +120 -0
- data/lib/soaspec/version.rb +1 -1
- data/test_rest.rb +76 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72616e1074159a6f95e6def516fd54d1b9bae9c2
|
4
|
+
data.tar.gz: c63d9d36c73c36e14dc817ec9f846e01bd0cf3ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d88345669ab61df3b26d28c3fad0e3ac860693426f348519f17e8e05eb89f1f7343085a81ed41b846251c167ff7a499ae7fbb435e84aaaead3ac4cef867777f
|
7
|
+
data.tar.gz: 7e63562503b905cceb8597d8d06947f774129df9631d0a9a9423e472dc3de174d52e9662c6b3987b2905fb4b1b285f2efcfb232c41d1b7838a4de7639d2d9574
|
data/.rubocop.yml
ADDED
data/ChangeLog
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
Version 0.0.23 / 2018-2-23
|
2
|
+
* Enhancements
|
3
|
+
* Created RestHandler class (Very messy and ugly still) to handle REST requests using style used for SOAP using Rest Client resource
|
4
|
+
|
1
5
|
Version 0.0.22 / 2018-2-15
|
2
6
|
* Enhancements
|
3
7
|
* Created new 'include_in_body' matcher to find value anywhere in response body (which could be a substring of an element)
|
data/Gemfile.lock
CHANGED
data/exe/soaspec-generate
CHANGED
File without changes
|
data/lib/soaspec.rb
CHANGED
@@ -104,6 +104,10 @@ module Soaspec
|
|
104
104
|
{}
|
105
105
|
end
|
106
106
|
|
107
|
+
def include_in_body?(response, expected)
|
108
|
+
response.to_xml.to_s.include? expected
|
109
|
+
end
|
110
|
+
|
107
111
|
# Attributes set at the root XML element of SOAP request
|
108
112
|
def root_attributes
|
109
113
|
nil
|
@@ -117,7 +121,6 @@ module Soaspec
|
|
117
121
|
temp_doc.remove_namespaces!
|
118
122
|
temp_doc.xpath(param[:xpath]).first
|
119
123
|
else
|
120
|
-
puts 'no strip' + param[:xpath]
|
121
124
|
param[:exchange].response.xpath(param[:xpath]).first
|
122
125
|
end
|
123
126
|
raise NoElementAtXpath, "No value at Xpath '#{param[:xpath]}'" unless result
|
data/lib/soaspec/matchers.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative 'xpath_not_found'
|
|
4
4
|
|
5
5
|
# TODO: Mathcers are specific to SOAP. Make generic for REST and others by using actual.api_class
|
6
6
|
|
7
|
+
# Whether response has any element with the provided value
|
7
8
|
RSpec::Matchers.define :contain_value do |expected|
|
8
9
|
match do |actual|
|
9
10
|
expect(actual.response.body.include_value?(expected)).to be true
|
@@ -14,9 +15,10 @@ RSpec::Matchers.define :contain_value do |expected|
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
# Whether substring exists in body of response (more general than above)
|
17
19
|
RSpec::Matchers.define :include_in_body do |expected|
|
18
20
|
match do |actual|
|
19
|
-
expect(actual.
|
21
|
+
expect(actual.api_class.include_in_body?(actual.response, expected)).to be true
|
20
22
|
end
|
21
23
|
|
22
24
|
failure_message do |actual|
|
@@ -24,6 +26,7 @@ RSpec::Matchers.define :include_in_body do |expected|
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
29
|
+
# Whether expected element exists in body
|
27
30
|
RSpec::Matchers.define :contain_key do |expected|
|
28
31
|
match do |actual|
|
29
32
|
expect(actual.response.body.include_key?(expected)).to be true
|
@@ -34,12 +37,19 @@ RSpec::Matchers.define :contain_key do |expected|
|
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
40
|
+
# Whether an element exists at expected xpath
|
37
41
|
RSpec::Matchers.define :have_element_at_xpath do |xpath|
|
38
42
|
match do |exchange|
|
39
|
-
expect { exchange[xpath] }.to_not raise_error
|
43
|
+
expect { exchange[xpath] }.to_not raise_error
|
44
|
+
end
|
45
|
+
|
46
|
+
failure_message do |actual|
|
47
|
+
"expected that #{actual.response.to_xml} would have element at xpath '#{xpath}'"
|
40
48
|
end
|
41
49
|
end
|
42
50
|
|
51
|
+
# Whether an element at xpath (defined by key) has value (defined by value).
|
52
|
+
# @param [Hash] expected_hash Xpath => Value pair (e.g. '//xmlns:GetWeatherResult' => 'Data Not Found')
|
43
53
|
RSpec::Matchers.define :have_xpath_value do |expected_hash|
|
44
54
|
match do |exchange|
|
45
55
|
expected_hash = Hash[*expected_hash.flatten] if expected_hash.is_a?(Array) # For some reason Array was occuring
|
@@ -0,0 +1,120 @@
|
|
1
|
+
|
2
|
+
require_relative 'tester'
|
3
|
+
require_relative 'hash_methods'
|
4
|
+
require_relative 'xpath_not_found'
|
5
|
+
|
6
|
+
module Soaspec
|
7
|
+
# Wraps around Savon client defining default values dependent on the soap request
|
8
|
+
class RestHandler < Tester
|
9
|
+
# Savon client used to make SOAP calls
|
10
|
+
attr_accessor :client
|
11
|
+
# SOAP Operation to use by default
|
12
|
+
attr_accessor :operation
|
13
|
+
|
14
|
+
# Options to log xml request and response
|
15
|
+
def logging_options
|
16
|
+
{
|
17
|
+
# See request and response. (Put this in traffic file)
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
# Default Savon options. See http://savonrb.com/version2/globals.html for details
|
22
|
+
# @return [Hash] Default Savon options for all BasicSoapHandler
|
23
|
+
def default_options
|
24
|
+
{
|
25
|
+
# method: :get
|
26
|
+
# headers: { content_type: 'text/plain' }
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Override in class
|
31
|
+
def base_url
|
32
|
+
''
|
33
|
+
end
|
34
|
+
|
35
|
+
# Add values to here when extending this class to have default REST options.
|
36
|
+
# See rest client resource for details
|
37
|
+
# @return [Hash] Options adding to & overriding defaults
|
38
|
+
def rest_resource_options
|
39
|
+
{
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
# Setup object to handle communicating with a particular SOAP WSDL
|
44
|
+
# @param [Hash] specific_options Options defining SOAP request. WSDL, authentication, see http://savonrb.com/version2/globals.html for list of options
|
45
|
+
def initialize(name, specific_options = {})
|
46
|
+
options = default_options.merge logging_options
|
47
|
+
options.merge! rest_resource_options
|
48
|
+
options.merge!(specific_options)
|
49
|
+
@resource = RestClient::Resource.new(base_url, options: options) # @resource[url_extension].get
|
50
|
+
super
|
51
|
+
end
|
52
|
+
|
53
|
+
def name(name)
|
54
|
+
@test_values = {}
|
55
|
+
@test_name = name
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
def override(request_parameters)
|
60
|
+
@test_values = request_parameters
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
# Used in together with Exchange request that passes such override parameters
|
65
|
+
def make_request(override_parameters)
|
66
|
+
test_values = override_parameters
|
67
|
+
test_values[:params] ||= {}
|
68
|
+
|
69
|
+
@resource[test_values[:suburl]].send(test_values[:method].to_s, test_values[:params])
|
70
|
+
end
|
71
|
+
|
72
|
+
def include_in_body?(response, expected)
|
73
|
+
response.body.include? expected
|
74
|
+
end
|
75
|
+
|
76
|
+
def status_code_for(response)
|
77
|
+
response.code
|
78
|
+
end
|
79
|
+
|
80
|
+
# Override this to specify elements that must be present in the response
|
81
|
+
# Will be used in 'success_scenarios' shared examples
|
82
|
+
# @return [Array] Array of symbols specifying element names
|
83
|
+
def mandatory_elements
|
84
|
+
[]
|
85
|
+
end
|
86
|
+
|
87
|
+
# Override this to specify xpath results that must be present in the response
|
88
|
+
# Will be used in 'success_scenarios' shared examples
|
89
|
+
# @return [Hash] Hash of 'xpath' => 'expected value' pairs
|
90
|
+
def mandatory_xpath_values
|
91
|
+
{}
|
92
|
+
end
|
93
|
+
|
94
|
+
# Attributes set at the root XML element of SOAP request
|
95
|
+
def root_attributes
|
96
|
+
nil
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns the value at the provided xpath
|
100
|
+
def xpath_value_for(param)
|
101
|
+
result =
|
102
|
+
if Soaspec::Environment.strip_namespaces? && !param[:xpath].include?(':')
|
103
|
+
temp_doc = param[:exchange].response.doc
|
104
|
+
temp_doc.remove_namespaces!
|
105
|
+
temp_doc.xpath(param[:xpath]).first
|
106
|
+
else
|
107
|
+
puts 'no strip' + param[:xpath]
|
108
|
+
param[:exchange].response.xpath(param[:xpath]).first
|
109
|
+
end
|
110
|
+
raise NoElementAtXpath, "No value at Xpath '#{param[:xpath]}'" unless result
|
111
|
+
result.inner_text
|
112
|
+
end
|
113
|
+
|
114
|
+
def value_from_path(exchange, path)
|
115
|
+
path = '//' + path if path[0] != '/'
|
116
|
+
xpath_value_for(exchange: exchange, xpath: path)
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
data/lib/soaspec/version.rb
CHANGED
data/test_rest.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
options = {
|
5
|
+
headers: {
|
6
|
+
# accept: "application/xml",
|
7
|
+
accept: "application/json"
|
8
|
+
# content_type: "application/json",
|
9
|
+
# log: Logger.new('logs/traffic.log')
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
RestClient.log = Logger.new('logs/traffic.log')
|
14
|
+
|
15
|
+
data_string = <<-EOF
|
16
|
+
{
|
17
|
+
"id": 1,
|
18
|
+
"category": {
|
19
|
+
"id": 0,
|
20
|
+
"name": "string"
|
21
|
+
},
|
22
|
+
"name": "doggie",
|
23
|
+
"photoUrls": [
|
24
|
+
"string"
|
25
|
+
],
|
26
|
+
"tags": [
|
27
|
+
{
|
28
|
+
"id": 0,
|
29
|
+
"name": "string"
|
30
|
+
}
|
31
|
+
],
|
32
|
+
"status": "available"
|
33
|
+
}
|
34
|
+
EOF
|
35
|
+
|
36
|
+
|
37
|
+
data = {
|
38
|
+
id: '1',
|
39
|
+
category: {
|
40
|
+
id: '1',
|
41
|
+
name: "test"
|
42
|
+
},
|
43
|
+
name: "cat",
|
44
|
+
photoUrls: [
|
45
|
+
"string"
|
46
|
+
],
|
47
|
+
tags: [
|
48
|
+
{
|
49
|
+
id: '2',
|
50
|
+
name: "cute"
|
51
|
+
}
|
52
|
+
],
|
53
|
+
status: "closed"
|
54
|
+
}
|
55
|
+
|
56
|
+
resource = RestClient::Resource.new('http://petstore.swagger.io/v2', options)
|
57
|
+
# begin
|
58
|
+
# response = resource['pet'].post(data)
|
59
|
+
# rescue RestClient::ExceptionWithResponse => e
|
60
|
+
# puts e.response
|
61
|
+
# end
|
62
|
+
|
63
|
+
begin
|
64
|
+
#response = resource['store/order/1'].get
|
65
|
+
#response = resource['store/inventory'].get
|
66
|
+
#
|
67
|
+
response = resource['pet/findByStatus?status=sold'].get(accept: 'application/xml')
|
68
|
+
#response = resource['pet'].post(data_string, additional_headers: { accept: "application/json"})
|
69
|
+
rescue RestClient::ExceptionWithResponse => e
|
70
|
+
puts e.response
|
71
|
+
end
|
72
|
+
|
73
|
+
#puts response.to_s
|
74
|
+
puts response.body
|
75
|
+
puts response.code
|
76
|
+
puts response.request
|
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.
|
4
|
+
version: 0.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SamuelGarrattIQA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,6 +135,7 @@ extra_rdoc_files: []
|
|
135
135
|
files:
|
136
136
|
- ".gitignore"
|
137
137
|
- ".rspec"
|
138
|
+
- ".rubocop.yml"
|
138
139
|
- ".travis.yml"
|
139
140
|
- CODE_OF_CONDUCT.md
|
140
141
|
- ChangeLog
|
@@ -155,6 +156,7 @@ files:
|
|
155
156
|
- lib/soaspec/file_helpers.rb
|
156
157
|
- lib/soaspec/hash_methods.rb
|
157
158
|
- lib/soaspec/matchers.rb
|
159
|
+
- lib/soaspec/rest_handler.rb
|
158
160
|
- lib/soaspec/soaspec_shared_examples.rb
|
159
161
|
- lib/soaspec/spec_logger.rb
|
160
162
|
- lib/soaspec/tester.rb
|
@@ -164,6 +166,7 @@ files:
|
|
164
166
|
- template/soap_template.xml
|
165
167
|
- test.wsdl
|
166
168
|
- test.xml
|
169
|
+
- test_rest.rb
|
167
170
|
- test_wsdl.rb
|
168
171
|
homepage: https://gitlab.com/samuel-garratt/soaspec
|
169
172
|
licenses:
|