mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add tests for multiple arguments
This commit is contained in:
parent
acea12cafb
commit
4043a76a07
1 changed files with 212 additions and 74 deletions
|
@ -3,125 +3,263 @@ require "../spec_helper"
|
|||
describe Spectator::Matchers::ContainMatcher do
|
||||
describe "#match?" do
|
||||
context "with a String" do
|
||||
context "against a matching string" do
|
||||
it "is true" do
|
||||
value = "foobarbaz"
|
||||
search = "bar"
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
|
||||
context "at the beginning" do
|
||||
context "one argument" do
|
||||
context "against a matching string" do
|
||||
it "is true" do
|
||||
value = "foobar"
|
||||
search = "foo"
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "at the end" do
|
||||
it "is true" do
|
||||
value = "foobar"
|
||||
value = "foobarbaz"
|
||||
search = "bar"
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "against a different string" do
|
||||
it "is false" do
|
||||
value = "foobar"
|
||||
search = "baz"
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
context "at the beginning" do
|
||||
it "is true" do
|
||||
value = "foobar"
|
||||
search = "foo"
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "against a matching character" do
|
||||
it "is true" do
|
||||
value = "foobar"
|
||||
search = 'o'
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
context "at the end" do
|
||||
it "is true" do
|
||||
value = "foobar"
|
||||
search = "bar"
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "at the beginning" do
|
||||
context "against a different string" do
|
||||
it "is false" do
|
||||
value = "foobar"
|
||||
search = "baz"
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "against a matching character" do
|
||||
it "is true" do
|
||||
value = "foobar"
|
||||
search = 'f'
|
||||
search = 'o'
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
|
||||
context "at the beginning" do
|
||||
it "is true" do
|
||||
value = "foobar"
|
||||
search = 'f'
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "at the end" do
|
||||
it "is true" do
|
||||
value = "foobar"
|
||||
search = 'r'
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "at the end" do
|
||||
it "is true" do
|
||||
context "against a different character" do
|
||||
it "is false" do
|
||||
value = "foobar"
|
||||
search = 'r'
|
||||
search = 'z'
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "against a different character" do
|
||||
it "is false" do
|
||||
value = "foobar"
|
||||
search = 'z'
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_false
|
||||
context "multiple arguments" do
|
||||
context "against matching strings" do
|
||||
it "is true" do
|
||||
value = "foobarbaz"
|
||||
search = {"foo", "bar", "baz"}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "against one matching string" do
|
||||
it "is false" do
|
||||
value = "foobarbaz"
|
||||
search = {"foo", "qux"}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "against no matching strings" do
|
||||
it "is false" do
|
||||
value = "foobar"
|
||||
search = {"baz", "qux"}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "against matching characters" do
|
||||
it "is true" do
|
||||
value = "foobarbaz"
|
||||
search = {'f', 'b', 'z'}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "against one matching character" do
|
||||
it "is false" do
|
||||
value = "foobarbaz"
|
||||
search = {'f', 'c', 'd'}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "against no matching characters" do
|
||||
it "is false" do
|
||||
value = "foobarbaz"
|
||||
search = {'c', 'd', 'e'}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "against a matching string and character" do
|
||||
it "is true" do
|
||||
value = "foobarbaz"
|
||||
search = {"foo", 'z'}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "against a matching string and non-matching character" do
|
||||
it "is false" do
|
||||
value = "foobarbaz"
|
||||
search = {"foo", 'c'}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "against a non-matching string and matching character" do
|
||||
it "is false" do
|
||||
value = "foobarbaz"
|
||||
search = {"qux", 'f'}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "against a non-matching string and character" do
|
||||
it "is false" do
|
||||
value = "foobarbaz"
|
||||
search = {"qux", 'c'}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with an Enumberable" do
|
||||
context "against an equal value" do
|
||||
it "is true" do
|
||||
array = %i[a b c]
|
||||
search = :b
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
|
||||
context "at the beginning" do
|
||||
context "one argument" do
|
||||
context "against an equal value" do
|
||||
it "is true" do
|
||||
array = %i[a b c]
|
||||
search = :a
|
||||
search = :b
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
|
||||
context "at the beginning" do
|
||||
it "is true" do
|
||||
array = %i[a b c]
|
||||
search = :a
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "at the end" do
|
||||
it "is true" do
|
||||
array = %i[a b c]
|
||||
search = :c
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "at the end" do
|
||||
it "is true" do
|
||||
context "against a different value" do
|
||||
it "is false" do
|
||||
array = %i[a b c]
|
||||
search = :c
|
||||
search = :z
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_true
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "against a different value" do
|
||||
it "is false" do
|
||||
array = %i[a b c]
|
||||
search = :z
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search})
|
||||
matcher.match?(partial).should be_false
|
||||
context "multiple arguments" do
|
||||
context "against equal values" do
|
||||
it "is true" do
|
||||
array = %i[a b c]
|
||||
search = {:a, :b}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "against one equal value" do
|
||||
it "is false" do
|
||||
array = %i[a b c]
|
||||
search = {:a, :d}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "against no equal values" do
|
||||
it "is false" do
|
||||
array = %i[a b c]
|
||||
search = {:d, :e}
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(search)
|
||||
matcher.match?(partial).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue