Remove regex matcher - use case matcher

This commit is contained in:
Michael Miller 2019-05-08 16:39:00 -06:00
parent e4ec47f413
commit 7168b26218
5 changed files with 31 additions and 216 deletions

View file

@ -88,6 +88,28 @@ describe Spectator::Matchers::CaseMatcher do
match_data.matched?.should be_false
end
end
context "with a matching regex" do
it "is true" do
value = "foobar"
pattern = /foo/
partial = new_partial(value)
matcher = Spectator::Matchers::CaseMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.matched?.should be_true
end
end
context "with a non-matching regex" do
it "is false" do
value = "foo"
pattern = /bar/
partial = new_partial(value)
matcher = Spectator::Matchers::CaseMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.matched?.should be_false
end
end
end
end
@ -116,14 +138,6 @@ describe Spectator::Matchers::CaseMatcher do
end
describe "#message" do
it "mentions ===" do
value = 42
partial = new_partial(value)
matcher = Spectator::Matchers::CaseMatcher.new(value)
match_data = matcher.match(partial)
match_data.message.should contain("===")
end
it "contains the actual label" do
value = 42
label = "everything"
@ -155,14 +169,6 @@ describe Spectator::Matchers::CaseMatcher do
end
describe "#negated_message" do
it "mentions ===" do
value = 42
partial = new_partial(value)
matcher = Spectator::Matchers::CaseMatcher.new(value)
match_data = matcher.match(partial)
match_data.negated_message.should contain("===")
end
it "contains the actual label" do
value = 42
label = "everything"

View file

@ -1,147 +0,0 @@
require "../spec_helper"
describe Spectator::Matchers::RegexMatcher do
describe "#match" do
it "compares using #=~" do
spy = SpySUT.new
partial = new_partial(spy)
matcher = Spectator::Matchers::RegexMatcher.new(/foobar/)
matcher.match(partial)
spy.match_call_count.should be > 0
end
context "returned MatchData" do
describe "#matched?" do
context "with a matching pattern" do
it "is true" do
value = "foobar"
pattern = /foo/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.matched?.should be_true
end
end
context "with a non-matching pattern" do
it "is false" do
value = "foo"
pattern = /bar/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.matched?.should be_false
end
end
end
describe "#values" do
context "expected" do
it "is the expected value" do
value = "foo"
pattern = /bar/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(pattern)
end
end
context "actual" do
it "is the actual value" do
value = "foo"
pattern = /bar/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value)
end
end
end
describe "#message" do
it "mentions =~" do
value = "foobar"
pattern = /foo/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.message.should contain("=~")
end
it "contains the actual label" do
value = "foobar"
label = "different"
pattern = /foo/
partial = new_partial(value, label)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.message.should contain(label)
end
it "contains the expected label" do
value = "foobar"
label = "different"
pattern = /foo/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern, label)
match_data = matcher.match(partial)
match_data.message.should contain(label)
end
context "when expected label is omitted" do
it "contains stringified form of expected value" do
value = "foobar"
pattern = /foo/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.message.should contain(pattern.to_s)
end
end
end
describe "#negated_message" do
it "mentions =~" do
value = "foobar"
pattern = /foo/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.negated_message.should contain("=~")
end
it "contains the actual label" do
value = "foobar"
label = "different"
pattern = /foo/
partial = new_partial(value, label)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.negated_message.should contain(label)
end
it "contains the expected label" do
value = "foobar"
label = "different"
pattern = /foo/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern, label)
match_data = matcher.match(partial)
match_data.negated_message.should contain(label)
end
context "when expected label is omitted" do
it "contains stringified form of expected value" do
value = "foobar"
pattern = /foo/
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data.negated_message.should contain(pattern.to_s)
end
end
end
end
end
end