shard-spectator/spec/matchers/predicate_matcher_spec.cr

58 lines
1.8 KiB
Crystal
Raw Normal View History

2019-02-05 17:36:59 +00:00
require "../spec_helper"
describe Spectator::Matchers::PredicateMatcher do
describe "#match?" do
context "with a true predicate" do
it "is true" do
value = "foobar"
partial = new_partial(value)
2019-02-05 17:36:59 +00:00
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher.match?(partial).should be_true
end
end
context "with a false predicate" do
it "is false" do
value = "foobar"
partial = new_partial(value)
2019-02-05 17:36:59 +00:00
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(empty: Nil)).new
matcher.match?(partial).should be_false
end
end
end
describe "#message" do
it "contains the actual label" do
value = "foobar"
label = "blah"
partial = new_partial(value, label)
2019-02-05 17:36:59 +00:00
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher.message(partial).should contain(label)
end
it "contains stringified form of predicate" do
value = "foobar"
partial = new_partial(value)
2019-02-05 17:36:59 +00:00
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher.message(partial).should contain("ascii_only")
end
end
describe "#negated_message" do
it "contains the actual label" do
value = "foobar"
label = "blah"
partial = new_partial(value, label)
2019-02-05 17:36:59 +00:00
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher.negated_message(partial).should contain(label)
end
it "contains stringified form of predicate" do
value = "foobar"
partial = new_partial(value)
2019-02-05 17:36:59 +00:00
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher.negated_message(partial).should contain("ascii_only")
end
end
end