Sha256: 6a2be2ca6d27df3f3e621e48d0f8e84ce389db2f86e789bdba841f53d2bdd686
Contents?: true
Size: 1.08 KB
Versions: 8
Compression:
Stored size: 1.08 KB
Contents
require "dry-types" describe "type constraint" do context "by dry-type" do before do class Test::Foo extend Dry::Initializer::Mixin 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::Mixin param :foo, type: String end end.to raise_error(TypeError) end end end
Version data entries
8 entries across 8 versions & 1 rubygems