Sha256: b8c18c420299c2597a89733903321748595458831f5a07743d60a19c627ad092

Contents?: true

Size: 1.14 KB

Versions: 14

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

14 entries across 14 versions & 1 rubygems

Version Path
schemacop-3.0.30 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.29 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.28 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.27 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.26 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.25 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.24 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.23 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.22 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.21 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.20 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.19 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.18 test/unit/schemacop/v2/nil_dis_allow_test.rb
schemacop-3.0.17 test/unit/schemacop/v2/nil_dis_allow_test.rb