soaspec 0.0.25 → 0.0.26

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: 6c1bcd1af7218c1860476c8b8c71d8cb97236640
4
- data.tar.gz: ac9d54164f634b5887a22eb87779eb8e34c366b0
3
+ metadata.gz: f1a29b66931af96e20a87509ba9a1bf8e962c9de
4
+ data.tar.gz: 382f40037e5b95d6042ae733e2521f59ee27d8b0
5
5
  SHA512:
6
- metadata.gz: 16d7b2d861828838632b0ae50645b7ec87a55a63bef9513d626cfa4434e1db3c2b04b35edb58e217c40e7673acdbfa89979da4c6d9e88586b9c46e76ef07a8b3
7
- data.tar.gz: 3bcd6ae8198b0dc230dd4fe0a12ed219248a276a5e9a7f04b04a2317512cf838e2419ddbb11a749d72f4011655071ed7b5b06b68d7cfd495e71dbfa501041bfe
6
+ metadata.gz: d120628f376d440e1975c42dc1f9197db934b8117296dac4b365ccdf49353bc2e9b79dc4f1968d8d0945a7bdacfd50767dd8519cb38398346c36421de2d639b8
7
+ data.tar.gz: 4e146610d9e218227cca8a8625b577f660184fe5d09edcd6d67e24eefbdd78bf18d233bb4cdd32c5e83f7835a46d787fbd54b7ac0a5fdb40ef909517f171fe07
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.0.26 / 2018-3-5
2
+ * Refactorings
3
+ * Using methods to define mandatory_elements, mandatory_xpath_values, root_attributes, base_url. Please see specs. This is shorter to type and clearer
4
+
1
5
  Version 0.0.25 / 2018-2-25
2
6
  * Enhancements
3
7
  * Updated rest_handler to convert JSON and XML into Hash and use it in 'contain_value'. This still needs work.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.25)
4
+ soaspec (0.0.26)
5
5
  rest-client (>= 2.0)
6
6
  rspec (~> 3.0)
7
7
  rspec-its (>= 1.2.0)
@@ -0,0 +1,23 @@
1
+ module Soaspec
2
+ # Describes methods test handlers use to easily set attributes
3
+ # Some are included in 'success scenarios' and to configure the request sent
4
+ module Accessors
5
+
6
+ # Defines expected_mandatory_elements method used in 'success_scenarios' shared examples
7
+ # to indicate certain elements must be present
8
+ # @param [Array] elements Array of symbols specifying expected element names for 'success_scearios' in snakecase
9
+ def mandatory_elements(elements)
10
+ define_method('expected_mandatory_elements') do
11
+ elements
12
+ end
13
+ end
14
+
15
+ def mandatory_xpath_values(xpath_value_pairs)
16
+ raise ArgumentError('Hash of {xpath => expected values} expected ') unless xpath_value_pairs.is_a? Hash
17
+ define_method('expected_mandatory_xpath_values') do
18
+ xpath_value_pairs
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -2,15 +2,35 @@
2
2
  require_relative 'tester'
3
3
  require_relative 'hash_methods'
4
4
  require_relative 'xpath_not_found'
5
+ require_relative 'accessors'
5
6
 
6
7
  module Soaspec
8
+
9
+ # Accessors specific to SOAP handler
10
+ module SoapAccessors
11
+
12
+ def root_attributes(attributes)
13
+ define_method('request_root_attributes') do
14
+ attributes
15
+ end
16
+ end
17
+ end
18
+
7
19
  # Wraps around Savon client defining default values dependent on the soap request
8
20
  class BasicSoapHandler < Tester
21
+ extend Soaspec::Accessors
22
+ extend Soaspec::SoapAccessors
23
+
9
24
  # Savon client used to make SOAP calls
10
25
  attr_accessor :client
11
26
  # SOAP Operation to use by default
12
27
  attr_accessor :operation
13
28
 
29
+ # Attributes set at the root XML element of SOAP request
30
+ def request_root_attributes
31
+ nil
32
+ end
33
+
14
34
  # Options to log xml request and response
15
35
  def logging_options
16
36
  {
@@ -77,7 +97,7 @@ module Soaspec
77
97
  render_body = ERB.new(request_body).result(binding)
78
98
  @client.call(operation, xml: render_body) # Call the SOAP operation with the request XML provided
79
99
  elsif @request_option == :hash
80
- @client.call(operation, message: @default_hash.merge(test_values), attributes: root_attributes)
100
+ @client.call(operation, message: @default_hash.merge(test_values), attributes: request_root_attributes)
81
101
  end
82
102
  end
83
103
 
@@ -90,29 +110,10 @@ module Soaspec
90
110
  response.http.code
91
111
  end
92
112
 
93
- # Override this to specify elements that must be present in the response
94
- # Will be used in 'success_scenarios' shared examples
95
- # @return [Array] Array of symbols specifying element names
96
- def mandatory_elements
97
- []
98
- end
99
-
100
- # Override this to specify xpath results that must be present in the response
101
- # Will be used in 'success_scenarios' shared examples
102
- # @return [Hash] Hash of 'xpath' => 'expected value' pairs
103
- def mandatory_xpath_values
104
- {}
105
- end
106
-
107
113
  def include_in_body?(response, expected)
108
114
  response.to_xml.to_s.include? expected
109
115
  end
110
116
 
111
- # Attributes set at the root XML element of SOAP request
112
- def root_attributes
113
- nil
114
- end
115
-
116
117
  # Returns the value at the provided xpath
117
118
  def xpath_value_for(param)
118
119
  result =
@@ -25,16 +25,6 @@ class Exchange
25
25
  @test_name
26
26
  end
27
27
 
28
- # Elements a shared 'success scenario' is expected to have
29
- def mandatory_elements
30
- @api_class.mandatory_elements
31
- end
32
-
33
- # Elements a shared 'success scenario' is expected to have
34
- def mandatory_xpath_values
35
- @api_class.mandatory_xpath_values
36
- end
37
-
38
28
  # Returns response object from Api
39
29
  # For example for SOAP it will be a Savon response
40
30
  # response.body (body of response as Hash)
@@ -2,40 +2,41 @@
2
2
  require_relative 'tester'
3
3
  require_relative 'hash_methods'
4
4
  require_relative 'xpath_not_found'
5
+ require_relative 'accessors'
5
6
  require 'json'
6
7
  require 'nori'
7
8
 
8
9
  module Soaspec
10
+
11
+ # Accessors specific to REST handler
12
+ module RestAccessors
13
+
14
+ # Defines method 'base_url_value' containing base URL used in REST requests
15
+ # @param [String] url Base Url to use in REST requests. Suburl is appended to this
16
+ def base_url(url)
17
+ define_method('base_url_value') do
18
+ url
19
+ end
20
+ end
21
+ end
22
+
9
23
  # Wraps around Savon client defining default values dependent on the soap request
10
24
  class RestHandler < Tester
25
+ extend Soaspec::RestAccessors
26
+ extend Soaspec::Accessors
27
+
11
28
  # Savon client used to make SOAP calls
12
29
  attr_accessor :client
13
30
  # SOAP Operation to use by default
14
31
  attr_accessor :operation
15
32
 
16
- # Options to log xml request and response
17
- def logging_options
18
- {
19
- # See request and response. (Put this in traffic file)
20
- }
21
- end
22
-
23
- # Default Savon options. See https://github.com/rest-client/rest-client for details
24
- # @return [Hash] Default Savon options for all BasicSoapHandler
25
- def default_options
26
- {
27
- # method: :get
28
- # headers: { content_type: 'text/plain' }
29
- }
30
- end
31
-
32
- # Override in class
33
- def base_url
34
- ''
33
+ # Set through following method. Base URL in REST requests.
34
+ def base_url_value
35
+ nil
35
36
  end
36
37
 
37
38
  # Add values to here when extending this class to have default REST options.
38
- # See rest client resource for details
39
+ # See rest client resource at https://github.com/rest-client/rest-client for details
39
40
  # @return [Hash] Options adding to & overriding defaults
40
41
  def rest_resource_options
41
42
  {
@@ -45,10 +46,10 @@ module Soaspec
45
46
  # Setup object to handle communicating with a particular SOAP WSDL
46
47
  # @param [Hash] specific_options Options defining SOAP request. WSDL, authentication
47
48
  def initialize(name, specific_options = {})
48
- options = default_options.merge logging_options
49
- options.merge! rest_resource_options
49
+ raise "Base URL not set! Please set in class with 'base_url' method" unless base_url_value
50
+ options = rest_resource_options
50
51
  options.merge!(specific_options)
51
- @resource = RestClient::Resource.new(base_url, options) # @resource[url_extension].get
52
+ @resource = RestClient::Resource.new(base_url_value, options) # @resource[url_extension].get
52
53
  super
53
54
  end
54
55
 
@@ -92,6 +93,8 @@ module Soaspec
92
93
  end
93
94
 
94
95
  # Convert XML or JSON response into a Hash
96
+ # @param [String] response Response as a String (either in XML or JSON)
97
+ # @return [Hash]
95
98
  def extract_hash(response)
96
99
  raise "Empty Body. Can't assert on it" if response.body.empty?
97
100
  type = case response.body[0]
@@ -107,7 +110,7 @@ module Soaspec
107
110
  when :json
108
111
  JSON.parse(response.body).transform_keys_to_symbols
109
112
  when :xml
110
- parser = Nori.new(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym })
113
+ parser = Nori.new(convert_tags_to: lambda { |tag| tag.snakecase.to_sym })
111
114
  parser.parse(response.body)
112
115
  else
113
116
  raise "Neither XML nor JSON detected. It is #{type}. Don't know how to parse It is #{response.body}"
@@ -5,13 +5,27 @@ shared_examples_for 'success scenario' do
5
5
  expect(described_class.status_code).to eq 200
6
6
  end
7
7
  context 'has expected mandatory elements' do
8
- described_class.mandatory_elements.each do |mandatory_element|
8
+ described_class.api_class.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
+ # TODO: Remove this. Handle depracated method temporariliy
14
+ described_class.api_class.mandatory_elements.each do |mandatory_element|
15
+ puts "Overriding 'mandatory_elements' deprecated. Use new 'expected_mandatory_elements' instead of overriding this method"
16
+ it mandatory_element do
17
+ expect(described_class).to contain_key mandatory_element
18
+ end
19
+ end
20
+ end
21
+ described_class.api_class.expected_mandatory_xpath_values.each do |xpath, value|
22
+ it "has xpath '#{xpath}' equal to '#{value}'" do
23
+ expect(described_class).to have_xpath_value(xpath => value)
24
+ end
13
25
  end
14
- described_class.mandatory_xpath_values.each do |xpath, value|
26
+ # TODO: Remove deprecated method
27
+ described_class.api_class.mandatory_xpath_values.each do |xpath, value|
28
+ puts "Overriding 'mandatory_elements' deprecated. Use new 'expected_mandatory_elements' instead of overriding this method"
15
29
  it "has xpath '#{xpath}' equal to '#{value}'" do
16
30
  expect(described_class).to have_xpath_value(xpath => value)
17
31
  end
@@ -27,5 +27,29 @@ module Soaspec
27
27
  @template_name = name
28
28
  end
29
29
 
30
+ # Will be used in 'success_scenarios' shared examples.
31
+ # Set though 'mandatory_elements' method
32
+ # @return [Array] Array of symbols specifying element names
33
+ def expected_mandatory_elements
34
+ []
35
+ end
36
+
37
+ # Use this to set 'expected_mandatory_elements' see 'accessors'
38
+ def mandatory_elements
39
+ []
40
+ end
41
+
42
+ # Override this to specify xpath results that must be present in the response
43
+ # Will be used in 'success_scenarios' shared examples
44
+ # @return [Hash] Hash of 'xpath' => 'expected value' pairs
45
+ def expected_mandatory_xpath_values
46
+ {}
47
+ end
48
+
49
+ # Use this to set 'expected_mandatory_xpath_values' see 'accessors'
50
+ def mandatory_xpath_values
51
+ []
52
+ end
53
+
30
54
  end
31
55
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.25'
2
+ VERSION = '0.0.26'
3
3
  end
data/lib/soaspec.rb CHANGED
@@ -17,7 +17,7 @@ require 'soaspec/hash_methods'
17
17
  require 'soaspec/spec_logger'
18
18
  require 'soaspec/exe_helpers'
19
19
  require 'soaspec/rest_handler'
20
-
20
+ require 'soaspec/accessors'
21
21
 
22
22
  # Gem for handling SOAP and REST api tests
23
23
  module Soaspec
data/test.rb ADDED
@@ -0,0 +1,28 @@
1
+
2
+ module TestM
3
+ def do_something(text)
4
+ define_method('hi') do
5
+ puts 'hi' + text
6
+ end
7
+ end
8
+ end
9
+
10
+ class BaseTest
11
+ extend TestM
12
+ end
13
+
14
+ class Tester < BaseTest
15
+
16
+ do_something('sam')
17
+ end
18
+
19
+ class Tes < BaseTest
20
+ do_something 'dsfd'
21
+ end
22
+
23
+ test = Tester.new
24
+
25
+ coll = Tes.new
26
+
27
+ test.hi
28
+ coll.hi
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.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-01 00:00:00.000000000 Z
11
+ date: 2018-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,6 +151,7 @@ files:
151
151
  - exe/soaspec-init
152
152
  - exe/xml_to_yaml_file
153
153
  - lib/soaspec.rb
154
+ - lib/soaspec/accessors.rb
154
155
  - lib/soaspec/basic_soap_handler.rb
155
156
  - lib/soaspec/exchange.rb
156
157
  - lib/soaspec/exe_helpers.rb
@@ -164,6 +165,7 @@ files:
164
165
  - lib/soaspec/xpath_not_found.rb
165
166
  - soaspec.gemspec
166
167
  - template/soap_template.xml
168
+ - test.rb
167
169
  - test.wsdl
168
170
  - test.xml
169
171
  - test_rest.rb