Update NilMatcher to use MatchData and #match

This commit is contained in:
Michael Miller 2019-02-28 11:31:05 -07:00
parent 0dd66c8803
commit 94cbb9860a

View file

@ -1,55 +1,65 @@
require "../spec_helper" require "../spec_helper"
describe Spectator::Matchers::NilMatcher do describe Spectator::Matchers::NilMatcher do
describe "#match?" do describe "#match" do
context "with nil" do context "returned MatchData" do
it "is true" do describe "#matched?" do
value = nil.as(Bool?) context "with nil" do
partial = new_partial(value) it "is true" do
matcher = Spectator::Matchers::NilMatcher.new value = nil.as(Bool?)
matcher.match?(partial).should be_true 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
end
context "with not nil" do describe "#message" do
it "is false" do it "mentions nil" do
value = true.as(Bool?) partial = new_partial(42)
partial = new_partial(value) matcher = Spectator::Matchers::NilMatcher.new
matcher = Spectator::Matchers::NilMatcher.new match_data = matcher.match(partial)
matcher.match?(partial).should be_false 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
end
describe "#message" do describe "#negated_message" do
it "mentions nil" do it "mentions nil" do
partial = new_partial(42) partial = new_partial(42)
matcher = Spectator::Matchers::NilMatcher.new matcher = Spectator::Matchers::NilMatcher.new
matcher.message(partial).should contain("nil") match_data = matcher.match(partial)
end match_data.negated_message.should contain("nil")
end
it "contains the actual label" do it "contains the actual label" do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value, label) partial = new_partial(value, label)
matcher = Spectator::Matchers::NilMatcher.new matcher = Spectator::Matchers::NilMatcher.new
matcher.message(partial).should contain(label) match_data = matcher.match(partial)
end match_data.negated_message.should contain(label)
end 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)
end end
end end
end end