Module: Soaspec::HandlerAccessors
- Included in:
- ExchangeHandler
- Defined in:
- lib/soaspec/exchange_handlers/handler_accessors.rb
Overview
Describes methods test handlers use to easily set attributes Some are included in ‘success scenarios’ and to configure the request sent
Instance Method Summary collapse
-
#attribute(name, attribute = nil) ⇒ Object
Links an attribute to a meaningful method that can be accessed from Exchange class.
-
#convert_to_lower(set) ⇒ Object
All xpath will be done with XML that is converted to lower case You must then use lower case in the xpath’s to obtain the desired values.
-
#default_hash(hash) ⇒ Object
Set the default hash representing data to be used in making a request This will set the @request_option instance variable too.
-
#element(name, path) ⇒ Object
Links a particular path to a meaningful method that can be accessed from Exchange class.
-
#mandatory_elements(elements) ⇒ Object
Defines expected_mandatory_elements method used in ‘success_scenario’ shared examples to indicate certain elements must be present Or for a list.
-
#mandatory_json_values(json_value_pairs) ⇒ Object
Defines mandatory json path value pairs to be included in ‘success scenario’ shared example.
-
#mandatory_xpath_values(xpath_value_pairs) ⇒ Object
Defines mandatory xpaths value pairs to be included in ‘success scenario’ shared example.
-
#strip_namespaces(set) ⇒ Object
Whether to remove namespaces from response in Xpath assertion automatically For why this may not be a good thing in general see tenderlovemaking.com/2009/04/23/namespaces-in-xml.html This will be overridden if xpath has a ‘:’ in it.
-
#template_name(name) ⇒ Object
Set the request option type and the template name Erb is used to parse the template file, executing Ruby code in ‘<%= %>` blocks to work out the final request.
Instance Method Details
#attribute(name, attribute = nil) ⇒ Object
Links an attribute to a meaningful method that can be accessed from Exchange class. This will use the ‘value_from_path’ method which should be implemented by each ExchangeHandler
84 85 86 87 88 89 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 84 def attribute(name, attribute = nil) attribute_used = attribute || name.to_s define_method("__custom_path_#{name}") do |response| value_from_path(response, 'implicit', attribute: attribute_used) end end |
#convert_to_lower(set) ⇒ Object
All xpath will be done with XML that is converted to lower case You must then use lower case in the xpath’s to obtain the desired values
94 95 96 97 98 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 94 def convert_to_lower(set) return unless set define_method('convert_to_lower?') { true } end |
#default_hash(hash) ⇒ Object
Set the default hash representing data to be used in making a request This will set the @request_option instance variable too
115 116 117 118 119 120 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 115 def default_hash(hash) define_method('default_hash_value') do @request_option = :hash Soaspec.always_use_keys? ? hash.transform_keys_to_symbols : hash end end |
#element(name, path) ⇒ Object
Links a particular path to a meaningful method that can be accessed from Exchange class. This will use the ‘value_from_path’ method which should be implemented by each ExchangeHandler
73 74 75 76 77 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 73 def element(name, path) define_method("__custom_path_#{name}") do |response| value_from_path(response, path.to_s) end end |
#mandatory_elements(elements) ⇒ Object
Defines expected_mandatory_elements method used in ‘success_scenario’ shared examples to indicate certain elements must be present Or for a list
In test describe Exchange(:name) do
it_behaves_like 'success scenario' # Includes checks for mandatory elements
end
23 24 25 26 27 28 29 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 23 def mandatory_elements(elements) define_method('expected_mandatory_elements') do return [elements] if elements.is_a?(String) || elements.is_a?(Symbol) elements end end |
#mandatory_json_values(json_value_pairs) ⇒ Object
Defines mandatory json path value pairs to be included in ‘success scenario’ shared example
61 62 63 64 65 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 61 def mandatory_json_values(json_value_pairs) raise ArgumentError("Hash of {'jsonpath' => expected values} expected") unless json_value_pairs.is_a? Hash define_method('expected_mandatory_json_values') { json_value_pairs } end |
#mandatory_xpath_values(xpath_value_pairs) ⇒ Object
Defines mandatory xpaths value pairs to be included in ‘success scenario’ shared example
43 44 45 46 47 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 43 def mandatory_xpath_values(xpath_value_pairs) raise ArgumentError('Hash of {xpath => expected values} expected ') unless xpath_value_pairs.is_a? Hash define_method('expected_mandatory_xpath_values') { xpath_value_pairs } end |
#strip_namespaces(set) ⇒ Object
Whether to remove namespaces from response in Xpath assertion automatically For why this may not be a good thing in general see tenderlovemaking.com/2009/04/23/namespaces-in-xml.html This will be overridden if xpath has a ‘:’ in it
105 106 107 108 109 110 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 105 def strip_namespaces(set) return unless set # Whether to remove namespaces in xpath assertion automatically define_method('strip_namespaces?') { true } end |
#template_name(name) ⇒ Object
Set the request option type and the template name Erb is used to parse the template file, executing Ruby code in ‘<%= %>` blocks to work out the final request
125 126 127 128 129 130 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 125 def template_name(name) define_method('template_name_value') do @request_option = :template name end end |