mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Update HaveMatcher to use MatchData
This commit is contained in:
parent
a78b80ed1f
commit
6ab2aad532
2 changed files with 576 additions and 482 deletions
|
@ -1,16 +1,18 @@
|
||||||
require "../spec_helper"
|
require "../spec_helper"
|
||||||
|
|
||||||
describe Spectator::Matchers::HaveMatcher do
|
describe Spectator::Matchers::HaveMatcher do
|
||||||
describe "#match?" do
|
describe "#match" do
|
||||||
it "uses ===" do
|
it "uses ===" do
|
||||||
array = %i[a b c]
|
array = %i[a b c]
|
||||||
spy = SpySUT.new
|
spy = SpySUT.new
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({spy})
|
matcher = Spectator::Matchers::HaveMatcher.new({spy})
|
||||||
matcher.match?(partial).should be_true
|
matcher.match(partial)
|
||||||
spy.case_eq_call_count.should be > 0
|
spy.case_eq_call_count.should be > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "returned MatchData" do
|
||||||
|
describe "#matched?" do
|
||||||
context "with a String" do
|
context "with a String" do
|
||||||
context "one argument" do
|
context "one argument" do
|
||||||
context "against a matching string" do
|
context "against a matching string" do
|
||||||
|
@ -19,7 +21,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = "bar"
|
search = "bar"
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
context "at the beginning" do
|
context "at the beginning" do
|
||||||
|
@ -28,7 +31,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = "foo"
|
search = "foo"
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,7 +42,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = "bar"
|
search = "bar"
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -49,7 +54,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = "baz"
|
search = "baz"
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,7 +65,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = 'o'
|
search = 'o'
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
context "at the beginning" do
|
context "at the beginning" do
|
||||||
|
@ -68,7 +75,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = 'f'
|
search = 'f'
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,7 +86,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = 'r'
|
search = 'r'
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,7 +98,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = 'z'
|
search = 'z'
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -101,7 +111,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {"foo", "bar", "baz"}
|
search = {"foo", "bar", "baz"}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -111,7 +122,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {"foo", "qux"}
|
search = {"foo", "qux"}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -121,7 +133,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {"baz", "qux"}
|
search = {"baz", "qux"}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -131,7 +144,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {'f', 'b', 'z'}
|
search = {'f', 'b', 'z'}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -141,7 +155,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {'f', 'c', 'd'}
|
search = {'f', 'c', 'd'}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -151,7 +166,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {'c', 'd', 'e'}
|
search = {'c', 'd', 'e'}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -161,7 +177,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {"foo", 'z'}
|
search = {"foo", 'z'}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -171,7 +188,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {"foo", 'c'}
|
search = {"foo", 'c'}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -181,7 +199,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {"qux", 'f'}
|
search = {"qux", 'f'}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -191,7 +210,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {"qux", 'c'}
|
search = {"qux", 'c'}
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -205,7 +225,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = :b
|
search = :b
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
context "at the beginning" do
|
context "at the beginning" do
|
||||||
|
@ -214,7 +235,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = :a
|
search = :a
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -224,7 +246,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = :c
|
search = :c
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -235,7 +258,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = :z
|
search = :z
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -244,7 +268,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
array = %i[a b c]
|
array = %i[a b c]
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
|
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
context "at the beginning" do
|
context "at the beginning" do
|
||||||
|
@ -252,7 +277,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
array = [:a, 1, 2]
|
array = [:a, 1, 2]
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
|
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -261,7 +287,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
array = [0, 1, :c]
|
array = [0, 1, :c]
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
|
matcher = Spectator::Matchers::HaveMatcher.new({Symbol})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -271,7 +298,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
array = %i[a b c]
|
array = %i[a b c]
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({Int32})
|
matcher = Spectator::Matchers::HaveMatcher.new({Int32})
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -281,7 +309,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = /bar/i
|
search = /bar/i
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
context "at the beginning" do
|
context "at the beginning" do
|
||||||
|
@ -290,7 +319,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = /foo/i
|
search = /foo/i
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -300,7 +330,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = /baz/i
|
search = /baz/i
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -311,7 +342,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = /qux/i
|
search = /qux/i
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -323,7 +355,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {:a, :b}
|
search = {:a, :b}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
context "matching type" do
|
context "matching type" do
|
||||||
|
@ -333,7 +366,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {:a, Int32, /foo/i}
|
search = {:a, Int32, /foo/i}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -343,7 +377,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {:a, Int32, /bar/i}
|
search = {:a, Int32, /bar/i}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -355,7 +390,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {:a, Float32, /foo/i}
|
search = {:a, Float32, /foo/i}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -365,7 +401,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {:a, Float32, /bar/i}
|
search = {:a, Float32, /bar/i}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -377,7 +414,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {:a, :d}
|
search = {:a, :d}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -387,7 +425,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {:d, :e}
|
search = {:d, :e}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -397,7 +436,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {Symbol, String}
|
search = {Symbol, String}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -407,7 +447,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {Symbol, Float32}
|
search = {Symbol, Float32}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -417,7 +458,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {Float32, Bytes}
|
search = {Float32, Bytes}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -427,7 +469,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {/foo/i, /bar/i}
|
search = {/foo/i, /bar/i}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -437,7 +480,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {/foo/i, /qux/i}
|
search = {/foo/i, /qux/i}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -447,7 +491,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {/baz/i, /qux/i}
|
search = {/baz/i, /qux/i}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_false
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -457,13 +502,38 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = {:a, Int32, /foo/i}
|
search = {:a, Int32, /foo/i}
|
||||||
partial = new_partial(array)
|
partial = new_partial(array)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
matcher.match?(partial).should be_true
|
match_data = matcher.match(partial)
|
||||||
|
match_data.matched?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#values" do
|
||||||
|
context "subset" do
|
||||||
|
it "has the expected value" do
|
||||||
|
array = [:a, 42, "FOO"]
|
||||||
|
search = {:a, Int32, /foo/i}
|
||||||
|
partial = new_partial(array)
|
||||||
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
|
match_data = matcher.match(partial)
|
||||||
|
match_data.values[:subset].should eq(search)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "superset" do
|
||||||
|
it "has the actual value" do
|
||||||
|
array = [:a, 42, "FOO"]
|
||||||
|
search = {:a, Int32, /foo/i}
|
||||||
|
partial = new_partial(array)
|
||||||
|
matcher = Spectator::Matchers::HaveMatcher.new(search)
|
||||||
|
match_data = matcher.match(partial)
|
||||||
|
match_data.values[:superset].should eq(array)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#message" do
|
describe "#message" do
|
||||||
it "contains the actual label" do
|
it "contains the actual label" do
|
||||||
value = "foobar"
|
value = "foobar"
|
||||||
|
@ -471,7 +541,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
label = "everything"
|
label = "everything"
|
||||||
partial = new_partial(value, label)
|
partial = new_partial(value, label)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.message(partial).should contain(label)
|
match_data = matcher.match(partial)
|
||||||
|
match_data.message.should contain(label)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "contains the expected label" do
|
it "contains the expected label" do
|
||||||
|
@ -480,7 +551,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
label = "everything"
|
label = "everything"
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search}, label)
|
matcher = Spectator::Matchers::HaveMatcher.new({search}, label)
|
||||||
matcher.message(partial).should contain(label)
|
match_data = matcher.match(partial)
|
||||||
|
match_data.message.should contain(label)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when expected label is omitted" do
|
context "when expected label is omitted" do
|
||||||
|
@ -489,7 +561,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = "baz"
|
search = "baz"
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.message(partial).should contain(search)
|
match_data = matcher.match(partial)
|
||||||
|
match_data.message.should contain(search)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -501,7 +574,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
label = "everything"
|
label = "everything"
|
||||||
partial = new_partial(value, label)
|
partial = new_partial(value, label)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.negated_message(partial).should contain(label)
|
match_data = matcher.match(partial)
|
||||||
|
match_data.negated_message.should contain(label)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "contains the expected label" do
|
it "contains the expected label" do
|
||||||
|
@ -510,7 +584,8 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
label = "everything"
|
label = "everything"
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search}, label)
|
matcher = Spectator::Matchers::HaveMatcher.new({search}, label)
|
||||||
matcher.negated_message(partial).should contain(label)
|
match_data = matcher.match(partial)
|
||||||
|
match_data.negated_message.should contain(label)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when expected label is omitted" do
|
context "when expected label is omitted" do
|
||||||
|
@ -519,7 +594,10 @@ describe Spectator::Matchers::HaveMatcher do
|
||||||
search = "baz"
|
search = "baz"
|
||||||
partial = new_partial(value)
|
partial = new_partial(value)
|
||||||
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
matcher = Spectator::Matchers::HaveMatcher.new({search})
|
||||||
matcher.negated_message(partial).should contain(search)
|
match_data = matcher.match(partial)
|
||||||
|
match_data.negated_message.should contain(search)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,8 +7,7 @@ module Spectator::Matchers
|
||||||
struct HaveMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
struct HaveMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
||||||
# Determines whether the matcher is satisfied with the value given to it.
|
# Determines whether the matcher is satisfied with the value given to it.
|
||||||
# True is returned if the match was successful, false otherwise.
|
# True is returned if the match was successful, false otherwise.
|
||||||
def match?(partial)
|
private def match?(actual)
|
||||||
actual = partial.actual
|
|
||||||
if actual.is_a?(String)
|
if actual.is_a?(String)
|
||||||
match_string?(actual)
|
match_string?(actual)
|
||||||
else
|
else
|
||||||
|
@ -16,12 +15,6 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Determines whether the matcher is satisfied with the partial given to it.
|
|
||||||
# `MatchData` is returned that contains information about the match.
|
|
||||||
def match(partial) : MatchData
|
|
||||||
raise NotImplementedError.new("#match")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Checks if a `String` matches the expected values.
|
# Checks if a `String` matches the expected values.
|
||||||
# The `includes?` method is used for this check.
|
# The `includes?` method is used for this check.
|
||||||
private def match_string?(actual)
|
private def match_string?(actual)
|
||||||
|
@ -41,16 +34,39 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Determines whether the matcher is satisfied with the partial given to it.
|
||||||
|
# `MatchData` is returned that contains information about the match.
|
||||||
|
def match(partial)
|
||||||
|
values = ExpectedActual.new(partial, self)
|
||||||
|
MatchData.new(match?(values.actual), values)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Match data specific to this matcher.
|
||||||
|
private struct MatchData(ExpectedType, ActualType) < MatchData
|
||||||
|
# Creates the match data.
|
||||||
|
def initialize(matched, @values : ExpectedActual(ExpectedType, ActualType))
|
||||||
|
super(matched)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Information about the match.
|
||||||
|
def values
|
||||||
|
{
|
||||||
|
subset: @values.expected,
|
||||||
|
superset: @values.actual,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
# Describes the condition that satisfies the matcher.
|
# Describes the condition that satisfies the matcher.
|
||||||
# This is informational and displayed to the end-user.
|
# This is informational and displayed to the end-user.
|
||||||
def message(partial)
|
def message
|
||||||
"Expected #{partial.label} to include #{label}"
|
"#{@values.actual_label} includes #{@values.expected_label}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Describes the condition that won't satsify the matcher.
|
# Describes the condition that won't satsify the matcher.
|
||||||
# This is informational and displayed to the end-user.
|
# This is informational and displayed to the end-user.
|
||||||
def negated_message(partial)
|
def negated_message
|
||||||
"Expected #{partial.label} to not include #{label}"
|
"#{@values.actual_label} does not include #{@values.expected_label}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue