2019-02-05 17:36:59 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
describe Spectator::Matchers::PredicateMatcher do
|
2019-03-06 18:05:13 +00:00
|
|
|
describe "#match" do
|
|
|
|
context "returned MatchData" do
|
|
|
|
describe "#match?" do
|
|
|
|
context "with a true predicate" do
|
|
|
|
it "is true" do
|
|
|
|
value = "foobar"
|
|
|
|
partial = new_partial(value)
|
2019-06-02 05:39:23 +00:00
|
|
|
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, "ascii_only")
|
2019-03-06 18:05:13 +00:00
|
|
|
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)
|
2019-06-02 05:39:23 +00:00
|
|
|
matcher = Spectator::Matchers::PredicateMatcher.new({empty: Tuple.new}, "empty")
|
2019-03-06 18:05:13 +00:00
|
|
|
match_data = matcher.match(partial)
|
|
|
|
match_data.matched?.should be_false
|
|
|
|
end
|
|
|
|
end
|
2019-02-05 17:36:59 +00:00
|
|
|
end
|
|
|
|
|
2019-03-06 18:05:13 +00:00
|
|
|
describe "#values" do
|
|
|
|
it "contains a key for each expected attribute" do
|
|
|
|
value = "foobar"
|
|
|
|
partial = new_partial(value)
|
2019-06-02 05:39:23 +00:00
|
|
|
matcher = Spectator::Matchers::PredicateMatcher.new({empty: Tuple.new, ascii_only: Tuple.new}, "empty, ascii_only")
|
2019-03-06 18:05:13 +00:00
|
|
|
match_data = matcher.match(partial)
|
2019-03-22 17:53:20 +00:00
|
|
|
match_data_has_key?(match_data.values, :empty).should be_true
|
|
|
|
match_data_has_key?(match_data.values, :ascii_only).should be_true
|
2019-03-06 18:05:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the actual values" do
|
|
|
|
value = "foobar"
|
|
|
|
partial = new_partial(value)
|
2019-06-02 05:39:23 +00:00
|
|
|
matcher = Spectator::Matchers::PredicateMatcher.new({empty: Tuple.new, ascii_only: Tuple.new}, "empty, ascii_only")
|
2019-03-06 18:05:13 +00:00
|
|
|
match_data = matcher.match(partial)
|
2019-03-22 17:53:20 +00:00
|
|
|
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?)
|
2019-03-06 18:05:13 +00:00
|
|
|
end
|
2019-02-05 17:36:59 +00:00
|
|
|
end
|
|
|
|
|
2019-03-06 18:05:13 +00:00
|
|
|
describe "#message" do
|
|
|
|
it "contains the actual label" do
|
|
|
|
value = "foobar"
|
|
|
|
label = "blah"
|
|
|
|
partial = new_partial(value, label)
|
2019-06-02 05:39:23 +00:00
|
|
|
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, "ascii_only")
|
2019-03-06 18:05:13 +00:00
|
|
|
match_data = matcher.match(partial)
|
|
|
|
match_data.message.should contain(label)
|
|
|
|
end
|
2019-02-05 17:36:59 +00:00
|
|
|
|
2019-06-02 05:39:23 +00:00
|
|
|
it "contains the expected label" do
|
2019-03-06 18:05:13 +00:00
|
|
|
value = "foobar"
|
2019-06-02 05:39:23 +00:00
|
|
|
label = "blah"
|
2019-03-06 18:05:13 +00:00
|
|
|
partial = new_partial(value)
|
2019-06-02 05:39:23 +00:00
|
|
|
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, label)
|
2019-03-06 18:05:13 +00:00
|
|
|
match_data = matcher.match(partial)
|
2019-06-02 05:39:23 +00:00
|
|
|
match_data.message.should contain(label)
|
2019-03-06 18:05:13 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-05 17:36:59 +00:00
|
|
|
|
2019-03-06 18:05:13 +00:00
|
|
|
describe "#negated_message" do
|
|
|
|
it "contains the actual label" do
|
|
|
|
value = "foobar"
|
|
|
|
label = "blah"
|
|
|
|
partial = new_partial(value, label)
|
2019-06-02 05:39:23 +00:00
|
|
|
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, "ascii_only")
|
2019-03-06 18:05:13 +00:00
|
|
|
match_data = matcher.match(partial)
|
|
|
|
match_data.negated_message.should contain(label)
|
|
|
|
end
|
2019-02-05 17:36:59 +00:00
|
|
|
|
2019-06-02 05:39:23 +00:00
|
|
|
it "contains the expected label" do
|
2019-03-06 18:05:13 +00:00
|
|
|
value = "foobar"
|
2019-06-02 05:39:23 +00:00
|
|
|
label = "blah"
|
2019-03-06 18:05:13 +00:00
|
|
|
partial = new_partial(value)
|
2019-06-02 05:39:23 +00:00
|
|
|
matcher = Spectator::Matchers::PredicateMatcher.new({ascii_only: Tuple.new}, label)
|
2019-03-06 18:05:13 +00:00
|
|
|
match_data = matcher.match(partial)
|
2019-06-02 05:39:23 +00:00
|
|
|
match_data.negated_message.should contain(label)
|
2019-03-06 18:05:13 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-05 17:36:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|