2019-01-19 21:49:13 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
describe Spectator::Matchers::RegexMatcher do
|
|
|
|
describe "#match?" do
|
|
|
|
it "compares using #=~" do
|
|
|
|
spy = SpySUT.new
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(spy)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(/foobar/)
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
spy.match_call_count.should be > 0
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a matching pattern" do
|
|
|
|
it "is true" do
|
|
|
|
value = "foobar"
|
|
|
|
pattern = /foo/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a non-matching pattern" do
|
|
|
|
it "is false" do
|
|
|
|
value = "foo"
|
|
|
|
pattern = /bar/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#message" do
|
|
|
|
it "mentions =~" do
|
|
|
|
value = "foobar"
|
|
|
|
pattern = /foo/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
|
|
|
matcher.message(partial).should contain("=~")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contains the actual label" do
|
|
|
|
value = "foobar"
|
|
|
|
label = "different"
|
|
|
|
pattern = /foo/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value, label)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
|
|
|
matcher.message(partial).should contain(label)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contains the expected label" do
|
|
|
|
value = "foobar"
|
|
|
|
label = "different"
|
|
|
|
pattern = /foo/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-28 22:17:12 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern, label)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher.message(partial).should contain(label)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when expected label is omitted" do
|
|
|
|
it "contains stringified form of expected value" do
|
|
|
|
value = "foobar"
|
|
|
|
pattern = /foo/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
|
|
|
matcher.message(partial).should contain(pattern.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#negated_message" do
|
|
|
|
it "mentions =~" do
|
|
|
|
value = "foobar"
|
|
|
|
pattern = /foo/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
|
|
|
matcher.negated_message(partial).should contain("=~")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contains the actual label" do
|
|
|
|
value = "foobar"
|
|
|
|
label = "different"
|
|
|
|
pattern = /foo/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value, label)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
|
|
|
matcher.negated_message(partial).should contain(label)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contains the expected label" do
|
|
|
|
value = "foobar"
|
|
|
|
label = "different"
|
|
|
|
pattern = /foo/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-28 22:17:12 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern, label)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher.negated_message(partial).should contain(label)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when expected label is omitted" do
|
|
|
|
it "contains stringified form of expected value" do
|
|
|
|
value = "foobar"
|
|
|
|
pattern = /foo/
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-01-19 21:49:13 +00:00
|
|
|
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
|
|
|
matcher.negated_message(partial).should contain(pattern.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|