mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add spec for match
(regex) matcher
This commit is contained in:
parent
260e1884ab
commit
a32b511e0b
3 changed files with 119 additions and 1 deletions
109
spec/matchers/regex_matcher_spec.cr
Normal file
109
spec/matchers/regex_matcher_spec.cr
Normal file
|
@ -0,0 +1,109 @@
|
|||
require "../spec_helper"
|
||||
|
||||
describe Spectator::Matchers::RegexMatcher do
|
||||
describe "#match?" do
|
||||
it "compares using #=~" do
|
||||
spy = SpySUT.new
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(spy)
|
||||
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/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
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/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
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/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
||||
matcher.message(partial).should contain("=~")
|
||||
end
|
||||
|
||||
it "contains the actual label" do
|
||||
value = "foobar"
|
||||
label = "different"
|
||||
pattern = /foo/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(label, value)
|
||||
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/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::RegexMatcher.new(label, pattern)
|
||||
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/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
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/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
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/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(label, value)
|
||||
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/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::RegexMatcher.new(label, pattern)
|
||||
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/
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
|
||||
matcher.negated_message(partial).should contain(pattern.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue