Skip to content

Commit

Permalink
Test matcher descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
icy-arctic-fox committed Jan 2, 2025
1 parent ee36337 commit 7da497d
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 1 deletion.
7 changes: 7 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 @@ -65,6 +65,13 @@ Spectator.describe BeAMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeAMatcher(Int32).new
expect(matcher.to_s).to eq("be a Int32")
end
end

context "DSL" do
describe "`be_a`" do
context "with `.to`" do
Expand Down
16 changes: 16 additions & 0 deletions spec/spectator/matchers/built_in/be_between_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ Spectator.describe BeBetweenMatcher do
end
end

describe "#to_s" do
context "inclusive" do
it "returns the description" do
matcher = BeBetweenMatcher.new(40, 50)
expect(matcher.to_s).to eq "be between 40 and 50 (inclusive)"
end
end

context "exclusive" do
it "returns the description" do
matcher = BeBetweenMatcher.new(40, 50).exclusive
expect(matcher.to_s).to eq "be between 40 and 50 (exclusive)"
end
end
end

context "DSL" do
describe "`be_between`" do
it "is inclusive by default" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_blank_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ Spectator.describe BeBlankMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeBlankMatcher.new
expect(matcher.to_s).to eq("be blank")
end
end

context "DSL" do
describe "`be_blank`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_close_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ Spectator.describe BeCloseMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeCloseMatcher.new(1.0, 0.1)
expect(matcher.to_s).to eq("be within 0.1 of 1.0")
end
end

describe "DSL" do
describe "`be_close`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_empty_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ Spectator.describe BeEmptyMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeEmptyMatcher.new
expect(matcher.to_s).to eq("be empty")
end
end

context "DSL" do
describe "`be_empty`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_in_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ Spectator.describe BeInMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeInMatcher.new([1, 2, 3])
expect(matcher.to_s).to eq("be in [1, 2, 3]")
end
end

describe "DSL" do
describe "`be_in`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_infinite_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ Spectator.describe BeInfiniteMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeInfiniteMatcher.new
expect(matcher.to_s).to eq("be infinite")
end
end

context "DSL" do
describe "`be_infinite`" do
context "with `.to`" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ Spectator.describe BeInstanceOfMatcher do
end
end

describe "#to_s" do
it "returns the inspect string" do
matcher = BeInstanceOfMatcher(Int32).new
expect(matcher.to_s).to eq("be an instance of Int32")
end
end

describe "DSL" do
describe "`be_instance_of`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ Spectator.describe BeMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeMatcher.new(1)
expect(matcher.to_s).to eq("be 1 : Int32")
end
end

describe "DSL" do
describe "`be`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_nan_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ Spectator.describe BeNaNMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeNaNMatcher.new
expect(matcher.to_s).to eq("be NaN")
end
end

describe "DSL" do
describe "`be_nan`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_negative_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ Spectator.describe BeNegativeMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeNegativeMatcher.new
expect(matcher.to_s).to eq("be negative")
end
end

describe "DSL" do
describe "`be_negative`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_positive_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ Spectator.describe BePositiveMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BePositiveMatcher.new
expect(matcher.to_s).to eq("be positive")
end
end

describe "DSL" do
describe "`be_positive`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_truthy_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ Spectator.describe BeTruthyMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeTruthyMatcher.new
expect(matcher.to_s).to eq("be truthy")
end
end

context "DSL" do
describe "`be_truthy`" do
context "with `.to`" do
Expand Down
7 changes: 7 additions & 0 deletions spec/spectator/matchers/built_in/be_zero_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ Spectator.describe BeZeroMatcher do
end
end

describe "#to_s" do
it "returns the description" do
matcher = BeZeroMatcher.new
expect(matcher.to_s).to eq("be zero")
end
end

describe "DSL" do
describe "`be_zero`" do
context "with `.to`" do
Expand Down
16 changes: 16 additions & 0 deletions spec/spectator/matchers/built_in/match_matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ Spectator.describe MatchMatcher do
end
end

describe "#to_s" do
context "with a string" do
it "returns the description" do
matcher = MatchMatcher.new(/foo/)
expect(matcher.to_s).to eq("match /foo/")
end
end

context "with a regex" do
it "returns the description" do
matcher = MatchMatcher.new("foobar")
expect(matcher.to_s).to eq("match \"foobar\"")
end
end
end

describe "DSL" do
describe "`match`" do
context "with `.to`" do
Expand Down
2 changes: 1 addition & 1 deletion src/spectator/matchers/built_in/match_matcher.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Spectator::Matchers::BuiltIn
end

def to_s(io : IO) : Nil
io << "match " << @expected_value
io << "match " << description_of(@expected_value)
end
end
end

0 comments on commit 7da497d

Please sign in to comment.