Sha256: 31e0991c4b9a783723651a19724b57e3b0d9152eb6b066a282f84dbe06f02166
Contents?: true
Size: 1.81 KB
Versions: 6
Compression:
Stored size: 1.81 KB
Contents
require 'test_helper' module Schemacop class ValidatorHashTest < Minitest::Test def test_basic s = Schema.new do type :hash do req :one do type :integer end req :two do type :boolean end end end assert_nil s.validate!(one: 3, two: true) assert_verr { s.validate!(one: 3) } assert_verr { s.validate!(two: true) } assert_verr { s.validate!({}) } assert_verr { s.validate!(one: 3, two: true, three: 3) } assert_verr { s.validate!(one: 3, three: true) } end def test_nested s = Schema.new do type :hash do req :h do type :hash do req :i do type :integer end end end end end s.validate(h: { i: 3 }) assert_verr { s.validate!(h: { i: true }) } assert_verr { s.validate!(h: {}) } assert_verr { s.validate!({}) } assert_verr { s.validate!(g: { i: 3 }) } assert_verr { s.validate!(h: { j: 3 }) } end def test_req_opt s = Schema.new do type :hash do req :r do type :boolean end req? :r_nil do type :boolean end opt :o do type :boolean end opt! :o_nonnil do type :boolean end end end assert_nil s.validate!(r: true, r_nil: false) assert_nil s.validate!(r: true, r_nil: nil) assert_nil s.validate!(r: true, r_nil: false, o: false) assert_nil s.validate!(r: true, r_nil: false, o: nil) assert_verr { s.validate!(r: true, r_nil: false, o_nonnil: nil) } assert_verr { s.validate!(o: true) } assert_verr { s.validate!(r: nil, r_nil: false, o: true) } end end end
Version data entries
6 entries across 6 versions & 1 rubygems