Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register a boolean type as an alias of bool #457

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/dry/types/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ module Types
register("strict.bool", bool)
register("bool", bool)

register("boolean", bool)
register("strict.boolean", bool)

register("any", Any)
register("nominal.any", Any)
register("strict.any", Any)
Expand Down
20 changes: 20 additions & 0 deletions spec/dry/types/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@
end
end

describe "with Boolean" do
let(:boolean) { Dry::Types["strict.boolean"] }

it_behaves_like "Dry::Types::Nominal without primitive" do
let(:type) { boolean }
end

it "accepts true object" do
expect(boolean[true]).to be(true)
end

it "accepts false object" do
expect(boolean[false]).to be(false)
end

it "raises when input is not true or false" do
expect { boolean["false"] }.to raise_error(Dry::Types::ConstraintError, /"false" violates constraints/)
end
end

describe "with Date" do
let(:date) { Dry::Types["strict.date"] }

Expand Down