Skip to content

Commit

Permalink
Add DSL tests for be_a matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
icy-arctic-fox committed Jul 24, 2024
1 parent a64f9d4 commit 9536a4a
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions spec/spectator/matchers/built_in/be_a_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,62 @@ Spectator.describe Spectator::Matchers::BuiltIn::BeAMatcher do
expect(42).to be_a(Int32)
end.to be_successful
end

it "does not match if the value is not an instance of the type" do
expect do
expect("foo").to be_a(Int32)
end.not_to be_successful
end

it "does not match if the value is nil" do
expect do
expect(nil).to be_a(Int32)
end.not_to be_successful
end

it "matches if the value is a subclass of the type" do
expect do
expect(Child.new).to be_a(Base)
end.to be_successful
end

it "does not match if the value is a parent of the type" do
expect do
expect(Base.new).to be_a(Child)
end.not_to be_successful
end
end

describe "be_an" do
it "matches if the value is an instance of the type" do
expect do
expect(42).to be_an(Int32)
end.to be_successful
end

it "does not match if the value is not an instance of the type" do
expect do
expect("foo").to be_an(Int32)
end.not_to be_successful
end

it "does not match if the value is nil" do
expect do
expect(nil).to be_an(Int32)
end.not_to be_successful
end

it "matches if the value is a subclass of the type" do
expect do
expect(Child.new).to be_an(Base)
end.to be_successful
end

it "does not match if the value is a parent of the type" do
expect do
expect(Base.new).to be_an(Child)
end.not_to be_successful
end
end
end
end

0 comments on commit 9536a4a

Please sign in to comment.