soaspec 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94c09dc736076e7a885813bff6f82fb4542d5aee
4
- data.tar.gz: c8c9ab3703b8ed38358f2fd8d840d81d4fff4431
3
+ metadata.gz: 648bba6578889b06fd5b8c3a1871e2dff381eb5e
4
+ data.tar.gz: 8b508b96c93f1928a222c3c7a4980d23438aae12
5
5
  SHA512:
6
- metadata.gz: 82bf609a95402240f1af578266ca891f37f96d5f947b4fe48a99c2e35b94d1a2e5ea3be78b5c215a6de350dedfc7f91e83ec9a71b37fd7ed188f191c97a97f76
7
- data.tar.gz: 22c17de478c533f2d6a79c5a19276391d1dcfe877cae518fda76866b5961ea52ef47e0d239738a0f21772a25de09d20095184524ae381cb61184589cf358c234
6
+ metadata.gz: b76fcbd53b8be2780a0dc64af8cf59a04ac07b1e68c91ffdb9814aeea3e4cbdc442510ef88a88991d1c914b011a567d4b260b8a07e22c52e95e419f57d9e3616
7
+ data.tar.gz: 18e2478c0df3c22b3c247fb2ffe974987bb5a1e14979c67ce049d056889d6cab944945a486069906774fc30ce32798d3a64d3f71afb5cfa0a1303d4d0ea6f819
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ Version 0.0.9 / 2018-1-20
2
+ * Refactoring
3
+ * class_options -> savon_options - More specific
4
+ * default_operation -> operation - Not default anymore so better not in name
5
+ * Enhancements
6
+ * Made mandatory_xpath_values method to add to 'success sceanarios' shared example
7
+
1
8
  Version 0.0.8 / 2018-1-19
2
9
  * Enhancements
3
10
  * Added root_attributes method to add attribute to the root class
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.8)
4
+ soaspec (0.0.9)
5
5
  rest-client (>= 2.0)
6
6
  rspec (~> 3.0)
7
7
  savon (>= 2)
data/README.md CHANGED
@@ -22,18 +22,21 @@ Or install it yourself as:
22
22
  ## Todo
23
23
 
24
24
  Handle REST
25
- Give examples and convience methods for building classes for each SOAP or REST operation
26
- Potentially have in built use of vcr and http_stub gems
25
+ Give examples and convenience methods for building classes for each SOAP or REST operation
26
+ Potentially have in built use of 'vcr' and 'http_stub' gems
27
27
 
28
28
  ## Usage
29
29
 
30
- See specs for example of usage. This will be added to later.
30
+ * SOAP - this uses Savon behind the scenes. Some defaults are overridden. Please see 'basic_soap_handler.rb'-'default_options' method
31
+ for such defaults. When describing an API override this in 'savon_options' method
31
32
 
32
- It is recommended that a class be created representing a Web Service Operation or REST call. Then tests refer back to
33
- that class. See get_weather_web_service class in spec/soaspec/soap folder for example.
33
+ See specs for example of usage. This will be added to later.
34
34
 
35
35
  ### Recommended
36
36
 
37
+ It is recommended that a class be created representing a Web Service Operation or REST call. Then tests refer back to
38
+ that class. See 'weather_web_service.rb' class in spec/soaspec/soap folder for example.
39
+
37
40
  If you find having a large backtrace on errors or RSpec shared examples such as 'success scenarios' this can shorten the
38
41
  backtrace.
39
42
 
@@ -1,3 +1,4 @@
1
+
1
2
  require 'yaml'
2
3
  require_relative 'common'
3
4
  require_relative 'tester'
@@ -11,7 +12,7 @@ module Soaspec
11
12
  # Namespaces used in XML body
12
13
  attr_accessor :namespaces
13
14
  # SOAP Operation to use by default
14
- attr_accessor :default_operation
15
+ attr_accessor :operation
15
16
 
16
17
  # Options to log xml request and response
17
18
  def logging_options
@@ -23,18 +24,27 @@ module Soaspec
23
24
  }
24
25
  end
25
26
 
26
- # Default Savon options
27
+ # Default Savon options. See http://savonrb.com/version2/globals.html for details
28
+ # @return [Hash] Default Savon options for all BasicSoapHandler
27
29
  def default_options
28
30
  {
29
- ssl_verify_mode: :none,
30
- follow_redirects: true, # Necessary for many API calls
31
- soap_version: 2, # use SOAP 1.2. You will get 415 error if this set to default
32
- raise_errors: false
31
+ ssl_verify_mode: :none, # Easier for testing. Not so secure
32
+ follow_redirects: true, # Necessary for many API calls
33
+ soap_version: 2, # use SOAP 1.2. You will get 415 error if this is incorrect
34
+ raise_errors: false # HTTP errors not cause failure as often negative test scenarios expect not 200 response
35
+ # Things could go wrong if not set properly
36
+ # env_namespace: :soap, # Change environment namespace
37
+ # namespace_identifier: :tst, # Change namespace element
38
+ # element_form_default: :qualified # Populate each element with namespace
39
+ # namespace: 'http://Extended_namespace.xsd' change root namespace
40
+ # basic_auth: 'user', 'password'
33
41
  }
34
42
  end
35
43
 
36
- # Add values to here when extending this class
37
- def class_options
44
+ # Add values to here when extending this class to have default Savon options.
45
+ # See http://savonrb.com/version2/globals.html for details
46
+ # @return [Hash] Savon options adding to & overriding defaults
47
+ def savon_options
38
48
  {
39
49
  }
40
50
  end
@@ -44,24 +54,13 @@ module Soaspec
44
54
  def initialize(name, specific_options = {})
45
55
  super
46
56
  options = default_options.merge logging_options
47
- options.merge! class_options
57
+ options.merge! savon_options
48
58
  options.merge!(specific_options)
49
59
  @client = Savon.client(options)
50
60
  self.namespaces = {}
51
61
  @name = name
52
62
  end
53
63
 
54
- # Sends a call to the API (is being made obsolete)
55
- # @param [Hash] options Dictionary of key value pairs specifying what API call to make
56
- # @return [SavonResponse] Savon response from which areas (header, body, etc) of the SOAP response can be accessed
57
- # def call(options)
58
- # test_values = options[:overide_values]['request'] || {} # Empty hash if no specific request values are set
59
- # options[:operation] ||= self.default_operation
60
- # # Erb parses template file, executing Ruby code in `<% %>` blocks to work out final request
61
- # render_body = ERB.new(options[:template]).result(binding)
62
- # @client.call(options[:operation], xml: render_body ) # Call the SOAP operation with the request XML provided
63
- # end
64
-
65
64
  def name(name)
66
65
  @test_values = {}
67
66
  @test_name = name
@@ -81,14 +80,14 @@ module Soaspec
81
80
  test_values = test_values.transform_keys_to_symbols # Either string or symbol
82
81
  request_body = File.read('template/' + template_name + '.xml')
83
82
  render_body = ERB.new(request_body).result(binding)
84
- @client.call(default_operation, xml: render_body ) # Call the SOAP operation with the request XML provided
83
+ @client.call(operation, xml: render_body) # Call the SOAP operation with the request XML provided
85
84
  elsif @request_option == :hash
86
- @client.call(default_operation, message: @default_hash.merge(test_values), attributes: root_attributes)
85
+ @client.call(operation, message: @default_hash.merge(test_values), attributes: root_attributes)
87
86
  end
88
87
  end
89
88
 
90
89
  def to_s
91
- Soaspec::Environment.api_handler = self
90
+ Soaspec::Environment.api_handler = self # Sets this variable globally. This is used in 'Exchange' class
92
91
  @name
93
92
  end
94
93
 
@@ -106,11 +105,20 @@ module Soaspec
106
105
  end
107
106
 
108
107
  # Override this to specify elements that must be present in the response
109
- # Make it an Array of keys
108
+ # Will be used in 'success_scenarios' shared examples
109
+ # @return [Array] Array of symbols specifying element names
110
110
  def mandatory_elements
111
- nil
111
+ []
112
+ end
113
+
114
+ # Override this to specify xpath results that must be present in the response
115
+ # Will be used in 'success_scenarios' shared examples
116
+ # @return [Hash] Hash of 'xpath' => 'expected value' pairs
117
+ def mandatory_xpath_values
118
+ {}
112
119
  end
113
120
 
121
+ # Attributes set at the root XML element of SOAP request
114
122
  def root_attributes
115
123
  nil
116
124
  end
@@ -35,6 +35,11 @@ class Exchange
35
35
  @api_class.mandatory_elements
36
36
  end
37
37
 
38
+ # Elements a shared 'success scenario' is expected to have
39
+ def mandatory_xpath_values
40
+ @api_class.mandatory_xpath_values
41
+ end
42
+
38
43
  # Returns Savon response
39
44
  # response.body (body of response as Hash)
40
45
  # response.header (head of response as Hash)
@@ -1,6 +1,13 @@
1
1
 
2
2
  require_relative 'hash_methods'
3
3
 
4
+ def xpath_for(param)
5
+ # TODO: look a using Savon's xpath rather than converting to Nokogiri
6
+ result = param[:exchange].xml_doc.at_xpath(param[:xpath], Soaspec::Environment.api_handler.namespaces)
7
+ raise 'No value at Xpath' unless result
8
+ result
9
+ end
10
+
4
11
  RSpec::Matchers.define :contain_value do |expected|
5
12
  match do |actual|
6
13
  expect(actual.response.body.include_value?(expected)).to be true
@@ -21,14 +28,15 @@ RSpec::Matchers.define :contain_key do |expected|
21
28
  end
22
29
  end
23
30
 
24
- RSpec::Matchers.define :have_element_at_xpath do |expected|
31
+ RSpec::Matchers.define :have_element_at_xpath do |xpath|
25
32
  match do |exchange|
26
- expect(exchange.xml_doc.at_xpath(expected, Soaspec::Environment.api_handler.namespaces).content).not_to be_empty
33
+ expect(xpath_for(exchange: exchange, xpath: xpath).content).not_to be_empty
27
34
  end
28
35
  end
29
36
 
30
37
  RSpec::Matchers.define :have_xpath_value do |expected_hash|
31
38
  match do |exchange|
32
- expect(exchange.xml_doc.at_xpath(expected_hash.keys.first, Soaspec::Environment.api_handler.namespaces).content).to eq expected_hash.values.first
39
+ expected_hash = Hash[*expected_hash.flatten] if expected_hash.is_a?(Array) # For some reason Array was occuring
40
+ expect(xpath_for(exchange: exchange, xpath: expected_hash.keys.first).content).to eq expected_hash.values.first
33
41
  end
34
42
  end
@@ -4,13 +4,16 @@ shared_examples_for 'success scenario' do
4
4
  it 'has status code of 200' do
5
5
  expect(described_class.status_code).to eq 200
6
6
  end
7
- if described_class.mandatory_elements
8
- context 'has expected mandatory elements' do
9
- described_class.mandatory_elements.each do |mandatory_element|
10
- it mandatory_element do
11
- expect(described_class).to contain_key mandatory_element
12
- end
7
+ context 'has expected mandatory elements' do
8
+ described_class.mandatory_elements.each do |mandatory_element|
9
+ it mandatory_element do
10
+ expect(described_class).to contain_key mandatory_element
13
11
  end
14
12
  end
15
13
  end
14
+ context 'has expected xpath values' do
15
+ described_class.mandatory_xpath_values.each do |xpath_pair|
16
+ it { is_expected.to have_xpath_value xpath_pair }
17
+ end
18
+ end
16
19
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-19 00:00:00.000000000 Z
11
+ date: 2018-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler