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.
-
#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.
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
79 80 81 82 83 84 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 79 def attribute(name, attribute = nil) attribute_used = attribute ? 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
88 89 90 91 92 93 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 88 def convert_to_lower(set) return unless set define_method('convert_to_lower?') do true 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
68 69 70 71 72 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 68 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
22 23 24 25 26 27 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 22 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
In test describe Exchange(:name) do
it_behaves_like 'success scenario' # Includes json pair validation
end
56 57 58 59 60 61 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 56 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') do json_value_pairs end end |
#mandatory_xpath_values(xpath_value_pairs) ⇒ Object
Defines mandatory xpaths value pairs to be included in ‘success scenario’ shared example
In test describe Exchange(:name) do
it_behaves_like 'success scenario' # Includes xpath pair validation
end
39 40 41 42 43 44 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 39 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') do xpath_value_pairs end 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
99 100 101 102 103 104 105 |
# File 'lib/soaspec/exchange_handlers/handler_accessors.rb', line 99 def strip_namespaces(set) return unless set # Whether to remove namespaces in xpath assertion automatically define_method('strip_namespaces?') do true end end |