Fix predicate tests and add new ones for have_ variant

This commit is contained in:
Michael Miller 2019-06-01 23:39:23 -06:00
parent 091cbaa81a
commit 0164d2973f
2 changed files with 101 additions and 12 deletions

View file

@ -0,0 +1,87 @@
require "../spec_helper"
describe Spectator::Matchers::HavePredicateMatcher do
describe "#match" do
context "returned MatchData" do
describe "#match?" do
context "with a true predicate" do
it "is true" do
value = "foo\\bar"
partial = new_partial(value)
matcher = Spectator::Matchers::HavePredicateMatcher.new({back_references: Tuple.new}, "back_references")
match_data = matcher.match(partial)
match_data.matched?.should be_true
end
end
context "with a false predicate" do
it "is false" do
value = "foobar"
partial = new_partial(value)
matcher = Spectator::Matchers::HavePredicateMatcher.new({back_references: Tuple.new}, "back_references")
match_data = matcher.match(partial)
match_data.matched?.should be_false
end
end
end
describe "#values" do
it "contains a key for each expected attribute" do
value = "foobar"
partial = new_partial(value)
matcher = Spectator::Matchers::HavePredicateMatcher.new({back_references: Tuple.new}, "back_references")
match_data = matcher.match(partial)
match_data_has_key?(match_data.values, :back_references).should be_true
end
it "has the actual values" do
value = "foobar"
partial = new_partial(value)
matcher = Spectator::Matchers::HavePredicateMatcher.new({back_references: Tuple.new}, "back_references")
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data.values, :back_references)[:value].should eq(value.has_back_references?)
end
end
describe "#message" do
it "contains the actual label" do
value = "foobar"
label = "blah"
partial = new_partial(value, label)
matcher = Spectator::Matchers::HavePredicateMatcher.new({back_references: Tuple.new}, "back_references")
match_data = matcher.match(partial)
match_data.message.should contain(label)
end
it "contains the expected label" do
value = "foobar"
label = "blah"
partial = new_partial(value)
matcher = Spectator::Matchers::HavePredicateMatcher.new({back_references: Tuple.new}, label)
match_data = matcher.match(partial)
match_data.message.should contain(label)
end
end
describe "#negated_message" do
it "contains the actual label" do
value = "foobar"
label = "blah"
partial = new_partial(value, label)
matcher = Spectator::Matchers::HavePredicateMatcher.new({back_references: Tuple.new}, "back_references")
match_data = matcher.match(partial)
match_data.negated_message.should contain(label)
end
it "contains the expected label" do
value = "foobar"
label = "blah"
partial = new_partial(value)
matcher = Spectator::Matchers::HavePredicateMatcher.new({back_references: Tuple.new}, label)
match_data = matcher.match(partial)
match_data.negated_message.should contain(label)
end
end
end
end
end

View file

@ -8,7 +8,7 @@ describe Spectator::Matchers::PredicateMatcher do
it "is true" do
value = "foobar"
partial = new_partial(value)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, "ascii_only")
match_data = matcher.match(partial)
match_data.matched?.should be_true
end
@ -18,7 +18,7 @@ describe Spectator::Matchers::PredicateMatcher do
it "is false" do
value = "foobar"
partial = new_partial(value)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(empty: Nil)).new
matcher = Spectator::Matchers::PredicateMatcher.new({empty: Tuple.new}, "empty")
match_data = matcher.match(partial)
match_data.matched?.should be_false
end
@ -29,7 +29,7 @@ describe Spectator::Matchers::PredicateMatcher do
it "contains a key for each expected attribute" do
value = "foobar"
partial = new_partial(value)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(empty: Nil, ascii_only: Nil)).new
matcher = Spectator::Matchers::PredicateMatcher.new({empty: Tuple.new, ascii_only: Tuple.new}, "empty, ascii_only")
match_data = matcher.match(partial)
match_data_has_key?(match_data.values, :empty).should be_true
match_data_has_key?(match_data.values, :ascii_only).should be_true
@ -38,7 +38,7 @@ describe Spectator::Matchers::PredicateMatcher do
it "has the actual values" do
value = "foobar"
partial = new_partial(value)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(empty: Nil, ascii_only: Nil)).new
matcher = Spectator::Matchers::PredicateMatcher.new({empty: Tuple.new, ascii_only: Tuple.new}, "empty, ascii_only")
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data.values, :empty)[:value].should eq(value.empty?)
match_data_value_sans_prefix(match_data.values, :ascii_only)[:value].should eq(value.ascii_only?)
@ -50,17 +50,18 @@ describe Spectator::Matchers::PredicateMatcher do
value = "foobar"
label = "blah"
partial = new_partial(value, label)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, "ascii_only")
match_data = matcher.match(partial)
match_data.message.should contain(label)
end
it "contains stringified form of predicate" do
it "contains the expected label" do
value = "foobar"
label = "blah"
partial = new_partial(value)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, label)
match_data = matcher.match(partial)
match_data.message.should contain("ascii_only")
match_data.message.should contain(label)
end
end
@ -69,17 +70,18 @@ describe Spectator::Matchers::PredicateMatcher do
value = "foobar"
label = "blah"
partial = new_partial(value, label)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, "ascii_only")
match_data = matcher.match(partial)
match_data.negated_message.should contain(label)
end
it "contains stringified form of predicate" do
it "contains the expected label" do
value = "foobar"
label = "blah"
partial = new_partial(value)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(ascii_only: Nil)).new
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, label)
match_data = matcher.match(partial)
match_data.negated_message.should contain("ascii_only")
match_data.negated_message.should contain(label)
end
end
end