Sha256: 8c15022f6d4e5a914c758ea10d5a5122200073a5c205a27f426970f28bfcd2ea

Contents?: true

Size: 754 Bytes

Versions: 3

Compression:

Stored size: 754 Bytes

Contents

# -*- encoding : utf-8 -*-
module Pacto
  module Cops
    class BodyCop
      KNOWN_CLAUSES = [:request, :response]

      def self.validates(clause)
        fail ArgumentError, "Unknown clause: #{clause}" unless KNOWN_CLAUSES.include? clause
        @clause = clause
      end

      def self.investigate(request, response, contract)
        # eval "is a security risk" and local_variable_get is ruby 2.1+ only, so...
        body = { request: request, response: response }[@clause].body
        schema = contract.send(@clause).schema
        if schema && !schema.empty?
          schema['id'] = contract.file unless schema.key? 'id'
          JSON::Validator.fully_validate(schema, body, version: :draft3)
        end || []
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pacto-0.4.0.rc3 lib/pacto/cops/body_cop.rb
pacto-0.4.0.rc2 lib/pacto/cops/body_cop.rb
pacto-0.4.0.rc1 lib/pacto/cops/body_cop.rb