From 94cbb9860a3c976b437f304f334c2c1f8ef6bae4 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 28 Feb 2019 11:31:05 -0700 Subject: [PATCH] Update NilMatcher to use MatchData and #match --- spec/matchers/nil_matcher_spec.cr | 98 +++++++++++++++++-------------- 1 file changed, 54 insertions(+), 44 deletions(-) diff --git a/spec/matchers/nil_matcher_spec.cr b/spec/matchers/nil_matcher_spec.cr index 03b7e00..c9a6862 100644 --- a/spec/matchers/nil_matcher_spec.cr +++ b/spec/matchers/nil_matcher_spec.cr @@ -1,55 +1,65 @@ require "../spec_helper" describe Spectator::Matchers::NilMatcher do - describe "#match?" do - context "with nil" do - it "is true" do - value = nil.as(Bool?) - partial = new_partial(value) - matcher = Spectator::Matchers::NilMatcher.new - matcher.match?(partial).should be_true + describe "#match" do + context "returned MatchData" do + describe "#matched?" do + context "with nil" do + it "is true" do + value = nil.as(Bool?) + partial = new_partial(value) + matcher = Spectator::Matchers::NilMatcher.new + match_data = matcher.match(partial) + match_data.matched?.should be_true + end + end + + context "with not nil" do + it "is false" do + value = true.as(Bool?) + partial = new_partial(value) + matcher = Spectator::Matchers::NilMatcher.new + match_data = matcher.match(partial) + match_data.matched?.should be_false + end + end end - end - context "with not nil" do - it "is false" do - value = true.as(Bool?) - partial = new_partial(value) - matcher = Spectator::Matchers::NilMatcher.new - matcher.match?(partial).should be_false + describe "#message" do + it "mentions nil" do + partial = new_partial(42) + matcher = Spectator::Matchers::NilMatcher.new + match_data = matcher.match(partial) + match_data.message.should contain("nil") + end + + it "contains the actual label" do + value = 42 + label = "everything" + partial = new_partial(value, label) + matcher = Spectator::Matchers::NilMatcher.new + match_data = matcher.match(partial) + match_data.message.should contain(label) + end end - end - end - describe "#message" do - it "mentions nil" do - partial = new_partial(42) - matcher = Spectator::Matchers::NilMatcher.new - matcher.message(partial).should contain("nil") - end + describe "#negated_message" do + it "mentions nil" do + partial = new_partial(42) + matcher = Spectator::Matchers::NilMatcher.new + match_data = matcher.match(partial) + match_data.negated_message.should contain("nil") + end - it "contains the actual label" do - value = 42 - label = "everything" - partial = new_partial(value, label) - matcher = Spectator::Matchers::NilMatcher.new - matcher.message(partial).should contain(label) - end - end - - describe "#negated_message" do - it "mentions nil" do - partial = new_partial(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 = new_partial(value, label) - matcher = Spectator::Matchers::NilMatcher.new - matcher.negated_message(partial).should contain(label) + it "contains the actual label" do + value = 42 + label = "everything" + partial = new_partial(value, label) + matcher = Spectator::Matchers::NilMatcher.new + match_data = matcher.match(partial) + match_data.negated_message.should contain(label) + end + end end end end