Sha256: 515ec049c4cfc2cee3f759eba433f3fc51760ba4447b1ce7aed215f70f120b77

Contents?: true

Size: 910 Bytes

Versions: 1

Compression:

Stored size: 910 Bytes

Contents

module ApiValidator
  class Status < Base

    def validate(response)
      response_status = response.status
      _failed_assertions = failed_assertions(response_status)
      super.merge(
        :key => :response_status,
        :failed_assertions => _failed_assertions.map(&:to_hash),
        :diff => diff(response_status, _failed_assertions),
        :valid => _failed_assertions.empty?
      )
    end

    private

    def initialize_assertions(expected)
      @assertions = [ Assertion.new("", expected) ]
    end

    def failed_assertions(actual)
      assertions.select do |assertion|
        !assertion_valid?(assertion, actual)
      end
    end

    def diff(actual, _failed_assertions)
      _failed_assertions.map do |assertion|
        assertion = assertion.to_hash
        assertion[:op] = "replace"
        assertion[:current_value] = actual
        assertion
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api-validator-0.0.1 lib/api-validator/status.rb