Sha256: 7d9bb03be170f2750a95f35cc7454c8692cb5a589c32967a5044c5e806453346

Contents?: true

Size: 651 Bytes

Versions: 1

Compression:

Stored size: 651 Bytes

Contents

require "json-schema"

module JsonMatchers
  class Matcher
    def initialize(schema_path, **options)
      @schema_path = schema_path
      @options = options
    end

    def matches?(response)
      @response = response

      JSON::Validator.validate!(
        schema_path.to_s,
        response.body,
        options,
      )
    rescue JSON::Schema::ValidationError => ex
      @validation_failure_message = ex.message
      false
    rescue JSON::ParserError
      raise InvalidSchemaError
    end

    def validation_failure_message
      @validation_failure_message.to_s
    end

    private

    attr_reader :schema_path, :options
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
json_matchers-0.5.0 lib/json_matchers/matcher.rb