Sha256: bb2ce63fec1a90a51b81d71affc91edfb695f182539cfd208a527716fc2ea41c
Contents?: true
Size: 1.06 KB
Versions: 3
Compression:
Stored size: 1.06 KB
Contents
require "dry-types" describe "type constraint" do context "by dry-type" do before do class Test::Foo extend Dry::Initializer param :foo, Dry::Types["strict.string"], optional: true end end context "in case of mismatch" do subject { Test::Foo.new 1 } it "raises TypeError" do expect { subject }.to raise_error TypeError, /1/ end end context "in case of match" do subject { Test::Foo.new "foo" } it "completes the initialization" do expect { subject }.not_to raise_error end end context "if optional value not set" do subject { Test::Foo.new } it "not applicable to Dry::Initializer::UNDEFINED" do expect(subject.instance_variable_get(:@foo)) .to eq Dry::Initializer::UNDEFINED end end end context "by invalid constraint" do it "raises TypeError" do expect do class Test::Foo extend Dry::Initializer param :foo, type: String end end.to raise_error(TypeError) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dry-initializer-2.2.0 | spec/type_constraint_spec.rb |
dry-initializer-2.1.0 | spec/type_constraint_spec.rb |
dry-initializer-2.0.0 | spec/type_constraint_spec.rb |