lib/soaspec/basic_soap_handler.rb in soaspec-0.0.25 vs lib/soaspec/basic_soap_handler.rb in soaspec-0.0.26

- old
+ new

@@ -1,18 +1,38 @@ require_relative 'tester' require_relative 'hash_methods' require_relative 'xpath_not_found' +require_relative 'accessors' module Soaspec + + # Accessors specific to SOAP handler + module SoapAccessors + + def root_attributes(attributes) + define_method('request_root_attributes') do + attributes + end + end + end + # Wraps around Savon client defining default values dependent on the soap request class BasicSoapHandler < Tester + extend Soaspec::Accessors + extend Soaspec::SoapAccessors + # Savon client used to make SOAP calls attr_accessor :client # SOAP Operation to use by default attr_accessor :operation + # Attributes set at the root XML element of SOAP request + def request_root_attributes + nil + end + # Options to log xml request and response def logging_options { log: true, # See request and response. (Put this in traffic file) log_level: :debug, @@ -75,11 +95,11 @@ if @request_option == :template request_body = File.read('template/' + template_name + '.xml') render_body = ERB.new(request_body).result(binding) @client.call(operation, xml: render_body) # Call the SOAP operation with the request XML provided elsif @request_option == :hash - @client.call(operation, message: @default_hash.merge(test_values), attributes: root_attributes) + @client.call(operation, message: @default_hash.merge(test_values), attributes: request_root_attributes) end end def default_hash=(hash) @request_option = :hash @@ -88,30 +108,11 @@ def status_code_for(response) response.http.code end - # Override this to specify elements that must be present in the response - # Will be used in 'success_scenarios' shared examples - # @return [Array] Array of symbols specifying element names - def mandatory_elements - [] - end - - # Override this to specify xpath results that must be present in the response - # Will be used in 'success_scenarios' shared examples - # @return [Hash] Hash of 'xpath' => 'expected value' pairs - def mandatory_xpath_values - {} - end - def include_in_body?(response, expected) response.to_xml.to_s.include? expected - end - - # Attributes set at the root XML element of SOAP request - def root_attributes - nil end # Returns the value at the provided xpath def xpath_value_for(param) result = \ No newline at end of file