Sha256: d4763460c19a3de157205b7949d589845760f6202ee0934a41f6ac2341cc963c

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

module Soaspec
  # Describes methods test handlers use to easily set attributes
  # Some are included in 'success scenarios' and to configure the request sent
  module Accessors

    # Defines expected_mandatory_elements method used in 'success_scenario' shared examples
    # to indicate certain elements must be present
    # @param [Array] elements Array of symbols specifying expected element names for 'success scenario' in snakecase
    def mandatory_elements(elements)
      define_method('expected_mandatory_elements') do
        return [elements] if elements.is_a?(String) || elements.is_a?(Symbol)
        elements
      end
    end

    # Defines mandatory xpaths value pairs to be included in 'success scenario' shared example
    #
    # @example Inside class
    #   mandatory_xpath_values '//xmlns:GetWeatherResult' => 'Data Not Found'
    #
    # In test
    # describe Exchange(:name) do
    #   it_behaves_like 'success scenario' # Includes xpath pair validation
    # end
    #
    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

    # Defines mandatory json path value pairs to be included in 'success scenario' shared example
    #
    # @example Inside class
    #   mandatory_json_values '$..GetWeatherResult' => 'Found'
    #
    # In test
    # describe Exchange(:name) do
    #   it_behaves_like 'success scenario' # Includes json pair validation
    # end
    #
    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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soaspec-0.0.36 lib/soaspec/accessors.rb