Module: JSONResponseVerification

Defined in:
lib/json_response_verification.rb

Overview

include this module in WSDSL to add response verification methods.

Instance Method Summary collapse

Instance Method Details

#validate_hash_response(hash) ⇒ Array<TrueClass, FalseClass, Array<String>>

Validates a hash against the service’s response description.

Returns:

  • (Array<TrueClass, FalseClass, Array<String>>)

    True/false and an array of errors.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/json_response_verification.rb', line 9

def validate_hash_response(hash)
  errors = []
  # nodes without the arrays
  response.nodes.each do |node|
    if node.name
      # Verify that the named node exists in the hash
      unless hash.has_key?(node.name.to_s)
        errors << json_response_error(node, hash) 
        return [false, errors]
      end
    end
    errors += validate_hash_against_template_node(hash, node)
  end

  [errors.empty?, errors]
end