From 3bfaa07d4fbb99d5805d81110d3acb66c6118105 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 26 Jan 2019 16:41:21 -0700 Subject: [PATCH] Add spec for nil matcher --- spec/matchers/nil_matcher_spec.cr | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 spec/matchers/nil_matcher_spec.cr diff --git a/spec/matchers/nil_matcher_spec.cr b/spec/matchers/nil_matcher_spec.cr new file mode 100644 index 0000000..da65d8c --- /dev/null +++ b/spec/matchers/nil_matcher_spec.cr @@ -0,0 +1,55 @@ +require "../spec_helper" + +describe Spectator::Matchers::NilMatcher do + describe "#match?" do + context "with nil" do + it "is true" do + value = nil.as(Bool?) + partial = Spectator::Expectations::ValueExpectationPartial.new(value) + matcher = Spectator::Matchers::NilMatcher.new + matcher.match?(partial).should be_true + end + end + + context "with not nil" do + it "is false" do + value = true.as(Bool?) + partial = Spectator::Expectations::ValueExpectationPartial.new(value) + matcher = Spectator::Matchers::NilMatcher.new + matcher.match?(partial).should be_false + end + end + end + + describe "#message" do + it "mentions nil" do + partial = Spectator::Expectations::ValueExpectationPartial.new(42) + matcher = Spectator::Matchers::NilMatcher.new + matcher.message(partial).should contain("nil") + end + + it "contains the actual label" do + value = 42 + label = "everything" + partial = Spectator::Expectations::ValueExpectationPartial.new(label, value) + matcher = Spectator::Matchers::NilMatcher.new + matcher.message(partial).should contain(label) + end + end + + describe "#negated_message" do + it "mentions nil" do + partial = Spectator::Expectations::ValueExpectationPartial.new(42) + matcher = Spectator::Matchers::NilMatcher.new + matcher.negated_message(partial).should contain("nil") + end + + it "contains the actual label" do + value = 42 + label = "everything" + partial = Spectator::Expectations::ValueExpectationPartial.new(label, value) + matcher = Spectator::Matchers::NilMatcher.new + matcher.negated_message(partial).should contain(label) + end + end +end