Sha256: 17bd553228fe80ec08e2f23763f352d1beb09e50de2a22441cafc26e9cce751d

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe JSON::Validator do
  let(:schema) do
    {
      '$schema' => 'http://json-schema.org/draft-04/schema#',
      'properties' => {
        'email' => {
          'type' => ['string', 'null'],
          'format' => 'email',
        },
        'uri' => {
          'type' => ['string', 'null'],
          'format' => 'uri',
        },
      }
    }
  end

  context 'email validation' do
    it 'should not raise an error if valid' do
      expect{JSON::Validator.validate!(schema, 'email' => 'ceo@example.com')}.to_not raise_error
    end

    it 'should raise an error if invalid' do
      expect{JSON::Validator.validate!(schema, 'email' => 'example.com')}.to raise_error(JSON::Schema::ValidationError)
    end
  end

  context 'uri validation' do
    it 'should not raise an error if valid' do
      expect{JSON::Validator.validate!(schema, 'uri' => 'scheme://user:pass@host/path?query#fragment')}.to_not raise_error
    end

    it 'should raise an error if invalid' do
      expect{JSON::Validator.validate!(schema, 'uri' => 'example.com')}.to raise_error(JSON::Schema::ValidationError)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pupa-0.2.4 spec/refinements/json-schema_spec.rb
pupa-0.2.3 spec/refinements/json-schema_spec.rb