2019-02-01 23:43:18 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
describe Spectator::Matchers::HaveMatcher do
|
|
|
|
describe "#match?" do
|
2019-02-04 23:26:53 +00:00
|
|
|
it "uses ===" do
|
|
|
|
array = %i[a b c]
|
|
|
|
spy = SpySUT.new
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-04 23:26:53 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({spy})
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
spy.case_eq_call_count.should be > 0
|
|
|
|
end
|
|
|
|
|
2019-02-01 23:43:18 +00:00
|
|
|
context "with a String" do
|
2019-02-02 03:44:25 +00:00
|
|
|
context "one argument" do
|
|
|
|
context "against a matching string" do
|
|
|
|
it "is true" do
|
|
|
|
value = "foobarbaz"
|
|
|
|
search = "bar"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
context "at the beginning" do
|
|
|
|
it "is true" do
|
|
|
|
value = "foobar"
|
|
|
|
search = "foo"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
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"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against a different string" do
|
|
|
|
it "is false" do
|
2019-02-01 23:43:18 +00:00
|
|
|
value = "foobar"
|
2019-02-02 03:44:25 +00:00
|
|
|
search = "baz"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:29:13 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher.match?(partial).should be_false
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against a matching character" do
|
2019-02-01 23:43:18 +00:00
|
|
|
it "is true" do
|
|
|
|
value = "foobar"
|
2019-02-02 03:44:25 +00:00
|
|
|
search = 'o'
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:29:13 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
2019-02-02 03:44:25 +00:00
|
|
|
|
|
|
|
context "at the beginning" do
|
|
|
|
it "is true" do
|
|
|
|
value = "foobar"
|
|
|
|
search = 'f'
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
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'
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against a different character" do
|
|
|
|
it "is false" do
|
|
|
|
value = "foobar"
|
|
|
|
search = 'z'
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "multiple arguments" do
|
|
|
|
context "against matching strings" do
|
|
|
|
it "is true" do
|
|
|
|
value = "foobarbaz"
|
|
|
|
search = {"foo", "bar", "baz"}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against one matching string" do
|
|
|
|
it "is false" do
|
|
|
|
value = "foobarbaz"
|
|
|
|
search = {"foo", "qux"}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "against no matching strings" do
|
|
|
|
it "is false" do
|
2019-02-01 23:43:18 +00:00
|
|
|
value = "foobar"
|
2019-02-02 03:44:25 +00:00
|
|
|
search = {"baz", "qux"}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
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'}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against one matching character" do
|
|
|
|
it "is false" do
|
|
|
|
value = "foobarbaz"
|
|
|
|
search = {'f', 'c', 'd'}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
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'}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "against a matching string and character" do
|
2019-02-01 23:43:18 +00:00
|
|
|
it "is true" do
|
2019-02-02 03:44:25 +00:00
|
|
|
value = "foobarbaz"
|
|
|
|
search = {"foo", 'z'}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against a matching string and non-matching character" do
|
|
|
|
it "is false" do
|
|
|
|
value = "foobarbaz"
|
|
|
|
search = {"foo", 'c'}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
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'}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
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'}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an Enumberable" do
|
2019-02-02 03:44:25 +00:00
|
|
|
context "one argument" do
|
|
|
|
context "against an equal value" do
|
2019-02-01 23:43:18 +00:00
|
|
|
it "is true" do
|
|
|
|
array = %i[a b c]
|
2019-02-02 03:44:25 +00:00
|
|
|
search = :b
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:29:13 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
2019-02-02 03:44:25 +00:00
|
|
|
|
|
|
|
context "at the beginning" do
|
|
|
|
it "is true" do
|
|
|
|
array = %i[a b c]
|
|
|
|
search = :a
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.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
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against a different value" do
|
|
|
|
it "is false" do
|
2019-02-01 23:43:18 +00:00
|
|
|
array = %i[a b c]
|
2019-02-02 03:44:25 +00:00
|
|
|
search = :z
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:29:13 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher.match?(partial).should be_false
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against a matching type" do
|
|
|
|
it "is true" do
|
|
|
|
array = %i[a b c]
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
context "at the beginning" do
|
|
|
|
it "is true" do
|
|
|
|
array = [:a, 1, 2]
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "at the end" do
|
|
|
|
it "is true" do
|
|
|
|
array = [0, 1, :c]
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against a non-matching type" do
|
|
|
|
it "is false" do
|
|
|
|
array = %i[a b c]
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({Int32})
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against a matching regex" do
|
2019-02-01 23:43:18 +00:00
|
|
|
it "is true" do
|
2019-02-02 03:44:25 +00:00
|
|
|
array = %w[FOO BAR BAZ]
|
|
|
|
search = /bar/i
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
2019-02-02 03:44:25 +00:00
|
|
|
|
|
|
|
context "at the beginning" do
|
|
|
|
it "is true" do
|
|
|
|
array = %w[FOO BAR BAZ]
|
|
|
|
search = /foo/i
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
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
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against a non-matching regex" do
|
|
|
|
it "is false" do
|
|
|
|
array = %w[FOO BAR BAZ]
|
|
|
|
search = /qux/i
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "multiple arguments" do
|
|
|
|
context "against equal values" do
|
2019-02-01 23:43:18 +00:00
|
|
|
it "is true" do
|
2019-02-02 03:44:25 +00:00
|
|
|
array = %i[a b c]
|
|
|
|
search = {:a, :b}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
2019-02-02 03:44:25 +00:00
|
|
|
|
|
|
|
context "matching type" do
|
|
|
|
context "matching regex" do
|
|
|
|
it "is true" do
|
|
|
|
array = [:a, 42, "FOO"]
|
|
|
|
search = {:a, Int32, /foo/i}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
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}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
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}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
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}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against one equal value" do
|
|
|
|
it "is false" do
|
|
|
|
array = %i[a b c]
|
|
|
|
search = {:a, :d}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against no equal values" do
|
|
|
|
it "is false" do
|
|
|
|
array = %i[a b c]
|
|
|
|
search = {:d, :e}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against matching types" do
|
2019-02-01 23:43:18 +00:00
|
|
|
it "is true" do
|
2019-02-02 03:44:25 +00:00
|
|
|
array = [:a, 42, "FOO"]
|
|
|
|
search = {Symbol, String}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against one matching type" do
|
|
|
|
it "is false" do
|
|
|
|
array = [:a, 42, "FOO"]
|
|
|
|
search = {Symbol, Float32}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
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}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
|
|
|
matcher.match?(partial).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "against matching regexes" do
|
2019-02-01 23:43:18 +00:00
|
|
|
it "is true" do
|
|
|
|
array = %w[FOO BAR BAZ]
|
2019-02-02 03:44:25 +00:00
|
|
|
search = {/foo/i, /bar/i}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-02 03:44:25 +00:00
|
|
|
context "against one matching regex" do
|
|
|
|
it "is false" do
|
|
|
|
array = %w[FOO BAR BAZ]
|
|
|
|
search = {/foo/i, /qux/i}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
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}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
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"]
|
2019-02-04 23:20:35 +00:00
|
|
|
search = {:a, Int32, /foo/i}
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(array)
|
2019-02-02 03:44:25 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
|
|
|
matcher.match?(partial).should be_true
|
|
|
|
end
|
2019-02-01 23:43:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#message" do
|
|
|
|
it "contains the actual label" do
|
|
|
|
value = "foobar"
|
|
|
|
search = "baz"
|
|
|
|
label = "everything"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value, label)
|
2019-02-02 03:29:13 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.message(partial).should contain(label)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contains the expected label" do
|
|
|
|
value = "foobar"
|
|
|
|
search = "baz"
|
|
|
|
label = "everything"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-28 22:17:12 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search}, label)
|
2019-02-01 23:43:18 +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"
|
|
|
|
search = "baz"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:29:13 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.message(partial).should contain(search)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#negated_message" do
|
|
|
|
it "contains the actual label" do
|
|
|
|
value = "foobar"
|
|
|
|
search = "baz"
|
|
|
|
label = "everything"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value, label)
|
2019-02-02 03:29:13 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.negated_message(partial).should contain(label)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contains the expected label" do
|
|
|
|
value = "foobar"
|
|
|
|
search = "baz"
|
|
|
|
label = "everything"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-28 22:17:12 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search}, label)
|
2019-02-01 23:43:18 +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"
|
|
|
|
search = "baz"
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2019-02-02 03:29:13 +00:00
|
|
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
2019-02-01 23:43:18 +00:00
|
|
|
matcher.negated_message(partial).should contain(search)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|