Add tests for multiple arguments

This commit is contained in:
Michael Miller 2019-02-01 20:44:25 -07:00
parent 239779135f
commit ade4af0153

View file

@ -3,201 +3,453 @@ require "../spec_helper"
describe Spectator::Matchers::HaveMatcher do describe Spectator::Matchers::HaveMatcher do
describe "#match?" do describe "#match?" do
context "with a String" do context "with a String" do
context "against a matching string" do context "one argument" do
it "is true" do context "against a matching string" do
value = "foobarbaz"
search = "bar"
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true
end
context "at the beginning" do
it "is true" do it "is true" do
value = "foobar" value = "foobarbaz"
search = "foo"
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true
end
end
context "at the end" do
it "is true" do
value = "foobar"
search = "bar" search = "bar"
partial = Spectator::Expectations::ValueExpectationPartial.new(value) partial = Spectator::Expectations::ValueExpectationPartial.new(value)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true matcher.match?(partial).should be_true
end end
end
end
context "against a different string" do context "at the beginning" do
it "is false" do it "is true" do
value = "foobar" value = "foobar"
search = "baz" search = "foo"
partial = Spectator::Expectations::ValueExpectationPartial.new(value) partial = Spectator::Expectations::ValueExpectationPartial.new(value)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_false matcher.match?(partial).should be_true
end end
end end
context "against a matching character" do context "at the end" do
it "is true" do it "is true" do
value = "foobar" value = "foobar"
search = 'o' search = "bar"
partial = Spectator::Expectations::ValueExpectationPartial.new(value) partial = Spectator::Expectations::ValueExpectationPartial.new(value)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true matcher.match?(partial).should be_true
end
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::HaveMatcher.new({search})
matcher.match?(partial).should be_false
end
end
context "against a matching character" do
it "is true" do it "is true" do
value = "foobar" value = "foobar"
search = 'f' search = 'o'
partial = Spectator::Expectations::ValueExpectationPartial.new(value) partial = Spectator::Expectations::ValueExpectationPartial.new(value)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true matcher.match?(partial).should be_true
end end
context "at the beginning" do
it "is true" do
value = "foobar"
search = 'f'
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
matcher = Spectator::Matchers::HaveMatcher.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::HaveMatcher.new({search})
matcher.match?(partial).should be_true
end
end
end end
context "at the end" do context "against a different character" do
it "is true" do it "is false" do
value = "foobar" value = "foobar"
search = 'r' search = 'z'
partial = Spectator::Expectations::ValueExpectationPartial.new(value) partial = Spectator::Expectations::ValueExpectationPartial.new(value)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true matcher.match?(partial).should be_false
end end
end end
end end
context "against a different character" do context "multiple arguments" do
it "is false" do context "against matching strings" do
value = "foobar" it "is true" do
search = 'z' value = "foobarbaz"
partial = Spectator::Expectations::ValueExpectationPartial.new(value) search = {"foo", "bar", "baz"}
matcher = Spectator::Matchers::HaveMatcher.new({search}) partial = Spectator::Expectations::ValueExpectationPartial.new(value)
matcher.match?(partial).should be_false matcher = Spectator::Matchers::HaveMatcher.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::HaveMatcher.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::HaveMatcher.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::HaveMatcher.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::HaveMatcher.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::HaveMatcher.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::HaveMatcher.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::HaveMatcher.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::HaveMatcher.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::HaveMatcher.new(search)
matcher.match?(partial).should be_false
end
end end
end end
end end
context "with an Enumberable" do context "with an Enumberable" do
context "against an equal value" do context "one argument" do
it "is true" do context "against an equal value" do
array = %i[a b c]
search = :b
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true
end
context "at the beginning" do
it "is true" do it "is true" do
array = %i[a b c] array = %i[a b c]
search = :a search = :b
partial = Spectator::Expectations::ValueExpectationPartial.new(array) partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true matcher.match?(partial).should be_true
end end
end
context "at the end" do context "at the beginning" do
it "is true" do it "is true" do
array = %i[a b c] array = %i[a b c]
search = :c search = :a
partial = Spectator::Expectations::ValueExpectationPartial.new(array) partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true 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::HaveMatcher.new({search})
matcher.match?(partial).should be_true
end
end end
end end
end
context "against a different value" do context "against a different value" do
it "is false" do it "is false" do
array = %i[a b c] array = %i[a b c]
search = :z search = :z
partial = Spectator::Expectations::ValueExpectationPartial.new(array) partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_false matcher.match?(partial).should be_false
end end
end
context "against a matching type" do
it "is true" do
array = %i[a b c]
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
matcher.match?(partial).should be_true
end end
context "at the beginning" do context "against a matching type" do
it "is true" do it "is true" do
array = [:a, 1, 2] array = %i[a b c]
partial = Spectator::Expectations::ValueExpectationPartial.new(array) partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({Symbol}) matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
matcher.match?(partial).should be_true matcher.match?(partial).should be_true
end end
end
context "at the end" do context "at the beginning" do
it "is true" do it "is true" do
array = [0, 1, :c] array = [:a, 1, 2]
partial = Spectator::Expectations::ValueExpectationPartial.new(array) partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({Symbol}) matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
matcher.match?(partial).should be_true matcher.match?(partial).should be_true
end
end
context "at the end" do
it "is true" do
array = [0, 1, :c]
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
matcher.match?(partial).should be_true
end
end end
end end
end
context "against a non-matching type" do context "against a non-matching type" do
it "is false" do it "is false" do
array = %i[a b c] array = %i[a b c]
partial = Spectator::Expectations::ValueExpectationPartial.new(array) partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({Int32}) matcher = Spectator::Matchers::HaveMatcher.new({Int32})
matcher.match?(partial).should be_false matcher.match?(partial).should be_false
end end
end
context "against a matching regex" do
it "is true" do
array = %w[FOO BAR BAZ]
search = /bar/i
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true
end end
context "at the beginning" do context "against a matching regex" do
it "is true" do it "is true" do
array = %w[FOO BAR BAZ] array = %w[FOO BAR BAZ]
search = /foo/i search = /bar/i
partial = Spectator::Expectations::ValueExpectationPartial.new(array) partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true matcher.match?(partial).should be_true
end end
context "at the beginning" do
it "is true" do
array = %w[FOO BAR BAZ]
search = /foo/i
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true
end
end
context "at the end" do
it "is true" do
array = %w[FOO BAR BAZ]
search = /baz/i
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true
end
end
end end
context "at the end" do context "against a non-matching regex" do
it "is true" do it "is false" do
array = %w[FOO BAR BAZ] array = %w[FOO BAR BAZ]
search = /baz/i search = /qux/i
partial = Spectator::Expectations::ValueExpectationPartial.new(array) partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new({search}) matcher = Spectator::Matchers::HaveMatcher.new({search})
matcher.match?(partial).should be_true matcher.match?(partial).should be_false
end end
end end
end end
context "against a non-matching regex" do context "multiple arguments" do
it "is false" do context "against equal values" do
array = %w[FOO BAR BAZ] it "is true" do
search = /qux/i array = %i[a b c]
partial = Spectator::Expectations::ValueExpectationPartial.new(array) search = {:a, :b}
matcher = Spectator::Matchers::HaveMatcher.new({search}) partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher.match?(partial).should be_false matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_true
end
context "matching type" do
context "matching regex" do
it "is true" do
array = [:a, 42, "FOO"]
search = {:a, Int32, /foo/i}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_true
end
end
context "non-matching regex" do
it "is false" do
array = [:a, 42, "FOO"]
search = {:a, Int32, /bar/i}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_false
end
end
end
context "non-matching type" do
context "matching regex" do
it "is false" do
array = [:a, 42, "FOO"]
search = {:a, Float32, /foo/i}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_false
end
end
context "non-matching regex" do
it "is false" do
array = [:a, 42, "FOO"]
search = {:a, Float32, /bar/i}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_false
end
end
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::HaveMatcher.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::HaveMatcher.new(search)
matcher.match?(partial).should be_false
end
end
context "against matching types" do
it "is true" do
array = [:a, 42, "FOO"]
search = {Symbol, String}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_true
end
end
context "against one matching type" do
it "is false" do
array = [:a, 42, "FOO"]
search = {Symbol, Float32}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_false
end
end
context "against no matching types" do
it "is false" do
array = [:a, 42, "FOO"]
search = {Float32, Bytes}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_false
end
end
context "against matching regexes" do
it "is true" do
array = %w[FOO BAR BAZ]
search = {/foo/i, /bar/i}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_true
end
end
context "against one matching regex" do
it "is false" do
array = %w[FOO BAR BAZ]
search = {/foo/i, /qux/i}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_false
end
end
context "against no matching regexes" do
it "is false" do
array = %w[FOO BAR]
search = {/baz/i, /qux/i}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_false
end
end
context "against equal and matching type and regex" do
it "is true" do
array = [:a, 42, "FOO"]
search = {Symbol, Int32, String}
partial = Spectator::Expectations::ValueExpectationPartial.new(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
matcher.match?(partial).should be_true
end
end end
end end
end end