Sha256: fae61bac49687e5fd668ba20738f91b0a4e96c2edbf29ffc56d9c58baa4056e3

Contents?: true

Size: 596 Bytes

Versions: 1

Compression:

Stored size: 596 Bytes

Contents

module Match
  module Json
    module Schema
      module RspecMatchers
        RSpec::Matchers.define :match_json_schema do |expected|
          @error_message = ''

          match do |actual|
            begin
              JSON::Validator.validate!(expected, JSON.parse(actual.body, symbolize_names: true))
              true
            rescue JSON::Schema::ValidationError => e
              @error_message = e.message
              false
            end
          end

          failure_message do |_actual|
            @error_message
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
match-json-schema-0.2.1 lib/match/json/schema/rspec_matchers.rb