Sha256: cdc7c5f24bd8b6a77b419400f9860aa893ba75a2a954e94e6373d9c1b8351be9

Contents?: true

Size: 1.14 KB

Versions: 23

Compression:

Stored size: 1.14 KB

Contents

require 'test_helper'

# Note: A test for req and opt is part of validator_hash_test.rb

module Schemacop
  module V2
    class NilDisAllowTest < V2Test
      def test_req
        s = Schema.new do
          req? :o do
            type :boolean
          end

          req :r do
            type :boolean
          end
        end
        assert_nothing_raised { s.validate!(o: nil, r: false) }
        assert_nothing_raised { s.validate!(o: false, r: false) }
        assert_verr { s.validate!(o: true, r: nil) }
        assert_verr { s.validate!(o: nil, r: nil) }
        assert_verr { s.validate!(r: true) }
      end

      def test_opt
        s = Schema.new do
          opt :o do
            type :boolean
          end
          opt! :r do
            type :boolean
          end
        end
        assert_nothing_raised { s.validate!(o: nil, r: false) }
        assert_nothing_raised { s.validate!(o: false, r: false) }
        assert_nothing_raised { s.validate!(r: true) }
        assert_nothing_raised { s.validate!({}) }
        assert_verr { s.validate!(o: true, r: nil) }
        assert_verr { s.validate!(o: nil, r: nil) }
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
schemacop-3.0.16 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.15 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.14 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.13 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.12 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.11 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.10 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.9 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.8 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.7 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.6 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.5 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.4 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.3 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.2 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.1 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.0 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.0.rc5 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.0.rc4 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.0.rc3 test/unit/schemacop/v2/nil_dis_allow_test.rb