Sha256: 7feb53a83c803ea3773362690d7fccbe5d22cf77f7d8657734d334e176ccb71b

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

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

describe Pupa::Refinements do
  let(:schema) do
    {
      '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

6 entries across 6 versions & 1 rubygems

Version Path
pupa-0.2.2 spec/refinements/json-schema_spec.rb
pupa-0.2.1 spec/refinements/json-schema_spec.rb
pupa-0.2.0 spec/refinements/json-schema_spec.rb
pupa-0.1.11 spec/refinements/json-schema_spec.rb
pupa-0.1.10 spec/refinements/json-schema_spec.rb
pupa-0.1.9 spec/refinements/json-schema_spec.rb