Change how values are passed to helper

Working around a segfault (dunno why this fixes it).
This commit is contained in:
Michael Miller 2019-03-22 11:53:20 -06:00
parent d705ef657c
commit e7e1d0e084
24 changed files with 106 additions and 107 deletions

View file

@ -1,6 +1,6 @@
# Retrieves a value from match data given its key/label.
def match_data_value_with_key(match_data, key)
labeled_value = match_data.values.find { |v| v.label == key }
def match_data_value_with_key(match_data_values, key)
labeled_value = match_data_values.find { |v| v.label == key }
raise "#{key} is missing" unless labeled_value
labeled_value.value
end
@ -8,17 +8,13 @@ end
# Retrieves the string representation and base value
# from a `Spectator::Matchers::PrefixedMatchDataValue` (or similar)
# in the values returned by `Spectator::Matchers::MatchData#values`.
def match_data_value_sans_prefix(match_data, key)
prefix = match_data_value_with_key(match_data, key)
if prefix.responds_to?(:value)
{to_s: prefix.to_s, value: prefix.value}
else
{to_s: prefix.to_s, value: prefix}
end
def match_data_value_sans_prefix(match_data_values, key)
prefix = match_data_value_with_key(match_data_values, key)
{to_s: prefix.to_s, value: prefix.value}
end
# Check whether match data has a value with a specified key/label.
def match_data_has_key?(match_data, key)
found = match_data.values.find { |v| v.label == key }
def match_data_has_key?(match_data_values, key)
found = match_data_values.find { |v| v.label == key }
!!found
end

View file

@ -249,9 +249,9 @@ describe Spectator::Matchers::AttributesMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::AttributesMatcher.new(attributes)
match_data = matcher.match(partial)
match_data_has_key?(match_data, :"expected first").should be_true
match_data_has_key?(match_data, :"expected last").should be_true
match_data_has_key?(match_data, :"expected size").should be_true
match_data_has_key?(match_data.values, :"expected first").should be_true
match_data_has_key?(match_data.values, :"expected last").should be_true
match_data_has_key?(match_data.values, :"expected size").should be_true
end
it "contains a key for each actual value" do
@ -260,9 +260,9 @@ describe Spectator::Matchers::AttributesMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::AttributesMatcher.new(attributes)
match_data = matcher.match(partial)
match_data_has_key?(match_data, :"actual first").should be_true
match_data_has_key?(match_data, :"actual last").should be_true
match_data_has_key?(match_data, :"actual size").should be_true
match_data_has_key?(match_data.values, :"actual first").should be_true
match_data_has_key?(match_data.values, :"actual last").should be_true
match_data_has_key?(match_data.values, :"actual size").should be_true
end
it "has the expected values" do
@ -271,9 +271,9 @@ describe Spectator::Matchers::AttributesMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::AttributesMatcher.new(attributes)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :"expected first")[:value].should eq(attributes[:first])
match_data_value_sans_prefix(match_data, :"expected last")[:value].should eq(attributes[:last])
match_data_value_sans_prefix(match_data, :"expected size")[:value].should eq(attributes[:size])
match_data_value_sans_prefix(match_data.values, :"expected first")[:value].should eq(attributes[:first])
match_data_value_sans_prefix(match_data.values, :"expected last")[:value].should eq(attributes[:last])
match_data_value_sans_prefix(match_data.values, :"expected size")[:value].should eq(attributes[:size])
end
it "has the actual values" do
@ -282,9 +282,9 @@ describe Spectator::Matchers::AttributesMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::AttributesMatcher.new(attributes)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :"actual first")[:value].should eq(array.first)
match_data_value_sans_prefix(match_data, :"actual last")[:value].should eq(array.last)
match_data_value_sans_prefix(match_data, :"actual size")[:value].should eq(array.size)
match_data_value_sans_prefix(match_data.values, :"actual first")[:value].should eq(array.first)
match_data_value_sans_prefix(match_data.values, :"actual last")[:value].should eq(array.last)
match_data_value_sans_prefix(match_data.values, :"actual size")[:value].should eq(array.size)
end
end

View file

@ -99,7 +99,7 @@ describe Spectator::Matchers::CaseMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::CaseMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(expected)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(expected)
end
end
@ -110,7 +110,7 @@ describe Spectator::Matchers::CaseMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::CaseMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(actual)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(actual)
end
end
end

View file

@ -300,7 +300,7 @@ describe Spectator::Matchers::ContainMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::ContainMatcher.new(search)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :subset)[:value].should eq(search)
match_data_value_sans_prefix(match_data.values, :subset)[:value].should eq(search)
end
end
@ -311,7 +311,7 @@ describe Spectator::Matchers::ContainMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::ContainMatcher.new(search)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :superset)[:value].should eq(array)
match_data_value_sans_prefix(match_data.values, :superset)[:value].should eq(array)
end
end
end

View file

@ -32,7 +32,7 @@ describe Spectator::Matchers::EmptyMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::EmptyMatcher.new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should eq("[]")
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should eq("[]")
end
end
@ -42,7 +42,7 @@ describe Spectator::Matchers::EmptyMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::EmptyMatcher.new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(array)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(array)
end
end
end

View file

@ -213,7 +213,7 @@ describe Spectator::Matchers::EndWithMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::EndWithMatcher.new(last)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(last)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(last)
end
end
@ -224,7 +224,7 @@ describe Spectator::Matchers::EndWithMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::EndWithMatcher.new(last)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(value)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value)
end
end
end
@ -237,7 +237,7 @@ describe Spectator::Matchers::EndWithMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::EndWithMatcher.new(last)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(last)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(last)
end
end
@ -248,7 +248,7 @@ describe Spectator::Matchers::EndWithMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::EndWithMatcher.new(last)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(array.last)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(array.last)
end
end
@ -259,7 +259,7 @@ describe Spectator::Matchers::EndWithMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::EndWithMatcher.new(last)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :list)[:value].should eq(array)
match_data_value_sans_prefix(match_data.values, :list)[:value].should eq(array)
end
end
end

View file

@ -76,7 +76,7 @@ describe Spectator::Matchers::EqualityMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(expected)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(expected)
end
end
@ -86,7 +86,7 @@ describe Spectator::Matchers::EqualityMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(actual)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(actual)
end
end
end

View file

@ -94,7 +94,7 @@ describe Spectator::Matchers::ExceptionMatcher do
partial = new_block_partial { raise ArgumentError.new }
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Nil).new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :"expected type")[:value].should eq(KeyError)
match_data_value_sans_prefix(match_data.values, :"expected type")[:value].should eq(KeyError)
end
end
@ -103,7 +103,7 @@ describe Spectator::Matchers::ExceptionMatcher do
partial = new_block_partial { raise ArgumentError.new }
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Nil).new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :"actual type")[:value].should eq(ArgumentError)
match_data_value_sans_prefix(match_data.values, :"actual type")[:value].should eq(ArgumentError)
end
context "when nothing is raised" do
@ -111,7 +111,7 @@ describe Spectator::Matchers::ExceptionMatcher do
partial = new_block_partial { 42 }
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Nil).new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :"actual type")[:value].should eq(Nil)
match_data_value_sans_prefix(match_data.values, :"actual type")[:value].should eq(Nil)
end
end
end
@ -122,7 +122,7 @@ describe Spectator::Matchers::ExceptionMatcher do
partial = new_block_partial { raise ArgumentError.new("foobar") }
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Regex).new(regex, "label")
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :"expected message")[:value].should eq(regex)
match_data_value_sans_prefix(match_data.values, :"expected message")[:value].should eq(regex)
end
end
@ -132,7 +132,7 @@ describe Spectator::Matchers::ExceptionMatcher do
partial = new_block_partial { raise ArgumentError.new(message) }
matcher = Spectator::Matchers::ExceptionMatcher(KeyError, Regex).new(/baz/, "label")
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :"actual message")[:value].should eq(message)
match_data_value_sans_prefix(match_data.values, :"actual message")[:value].should eq(message)
end
end
end

View file

@ -53,7 +53,7 @@ describe Spectator::Matchers::GreaterThanEqualMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(expected)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(expected)
end
it "is prefixed with >=" do
@ -62,7 +62,7 @@ describe Spectator::Matchers::GreaterThanEqualMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should start_with(">=")
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should start_with(">=")
end
end
@ -73,7 +73,7 @@ describe Spectator::Matchers::GreaterThanEqualMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(actual)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(actual)
end
context "when #matched? is true" do
@ -84,7 +84,7 @@ describe Spectator::Matchers::GreaterThanEqualMatcher do
matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data.matched?.should be_true # Sanity check.
match_data_value_sans_prefix(match_data, :actual)[:to_s].should start_with(">=")
match_data_value_sans_prefix(match_data.values, :actual)[:to_s].should start_with(">=")
end
end
@ -96,7 +96,7 @@ describe Spectator::Matchers::GreaterThanEqualMatcher do
matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data.matched?.should be_false # Sanity check.
match_data_value_sans_prefix(match_data, :actual)[:to_s].should start_with("<")
match_data_value_sans_prefix(match_data.values, :actual)[:to_s].should start_with("<")
end
end
end

View file

@ -53,7 +53,7 @@ describe Spectator::Matchers::GreaterThanMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::GreaterThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(expected)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(expected)
end
it "is prefixed with >" do
@ -62,7 +62,7 @@ describe Spectator::Matchers::GreaterThanMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::GreaterThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should start_with(">")
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should start_with(">")
end
end
@ -73,7 +73,7 @@ describe Spectator::Matchers::GreaterThanMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::GreaterThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(actual)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(actual)
end
context "when #matched? is true" do
@ -84,7 +84,7 @@ describe Spectator::Matchers::GreaterThanMatcher do
matcher = Spectator::Matchers::GreaterThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data.matched?.should be_true # Sanity check.
match_data_value_sans_prefix(match_data, :actual)[:to_s].should start_with(">")
match_data_value_sans_prefix(match_data.values, :actual)[:to_s].should start_with(">")
end
end
@ -96,7 +96,7 @@ describe Spectator::Matchers::GreaterThanMatcher do
matcher = Spectator::Matchers::GreaterThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data.matched?.should be_false # Sanity check.
match_data_value_sans_prefix(match_data, :actual)[:to_s].should start_with("<=")
match_data_value_sans_prefix(match_data.values, :actual)[:to_s].should start_with("<=")
end
end
end

View file

@ -67,7 +67,7 @@ describe Spectator::Matchers::HaveKeyMatcher do
partial = new_partial(tuple)
matcher = Spectator::Matchers::HaveKeyMatcher.new(key)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :key)[:value].should eq(key)
match_data_value_sans_prefix(match_data.values, :key)[:value].should eq(key)
end
end
@ -79,7 +79,7 @@ describe Spectator::Matchers::HaveKeyMatcher do
partial = new_partial(tuple)
matcher = Spectator::Matchers::HaveKeyMatcher.new(key)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(tuple.keys)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(tuple.keys)
end
end
@ -90,7 +90,7 @@ describe Spectator::Matchers::HaveKeyMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::HaveKeyMatcher.new(key)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(actual)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(actual)
end
end
end

View file

@ -518,7 +518,7 @@ describe Spectator::Matchers::HaveMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :subset)[:value].should eq(search)
match_data_value_sans_prefix(match_data.values, :subset)[:value].should eq(search)
end
end
@ -529,7 +529,7 @@ describe Spectator::Matchers::HaveMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::HaveMatcher.new(search)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :superset)[:value].should eq(array)
match_data_value_sans_prefix(match_data.values, :superset)[:value].should eq(array)
end
end
end

View file

@ -41,7 +41,7 @@ describe Spectator::Matchers::HaveValueMatcher do
partial = new_partial(hash)
matcher = Spectator::Matchers::HaveValueMatcher.new(value)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :value)[:value].should eq(value)
match_data_value_sans_prefix(match_data.values, :value)[:value].should eq(value)
end
end
@ -53,7 +53,7 @@ describe Spectator::Matchers::HaveValueMatcher do
partial = new_partial(hash)
matcher = Spectator::Matchers::HaveValueMatcher.new(value)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(hash.values)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(hash.values)
end
end
@ -64,7 +64,7 @@ describe Spectator::Matchers::HaveValueMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::HaveValueMatcher.new(value)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(actual)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(actual)
end
end
end

View file

@ -76,7 +76,7 @@ describe Spectator::Matchers::InequalityMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::InequalityMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(expected)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(expected)
end
it "is prefixed with 'Not'" do
@ -84,7 +84,7 @@ describe Spectator::Matchers::InequalityMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::InequalityMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should start_with("Not")
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should start_with("Not")
end
end
@ -94,7 +94,7 @@ describe Spectator::Matchers::InequalityMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::InequalityMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(actual)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(actual)
end
end
end

View file

@ -53,7 +53,7 @@ describe Spectator::Matchers::LessThanEqualMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::LessThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(expected)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(expected)
end
it "is prefixed with <=" do
@ -62,7 +62,7 @@ describe Spectator::Matchers::LessThanEqualMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::LessThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should start_with("<=")
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should start_with("<=")
end
end
@ -73,7 +73,7 @@ describe Spectator::Matchers::LessThanEqualMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::LessThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(actual)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(actual)
end
context "when #matched? is true" do
@ -84,7 +84,7 @@ describe Spectator::Matchers::LessThanEqualMatcher do
matcher = Spectator::Matchers::LessThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data.matched?.should be_true # Sanity check.
match_data_value_sans_prefix(match_data, :actual)[:to_s].should start_with("<=")
match_data_value_sans_prefix(match_data.values, :actual)[:to_s].should start_with("<=")
end
end
@ -96,7 +96,7 @@ describe Spectator::Matchers::LessThanEqualMatcher do
matcher = Spectator::Matchers::LessThanEqualMatcher.new(expected)
match_data = matcher.match(partial)
match_data.matched?.should be_false # Sanity check.
match_data_value_sans_prefix(match_data, :actual)[:to_s].should start_with(">")
match_data_value_sans_prefix(match_data.values, :actual)[:to_s].should start_with(">")
end
end
end

View file

@ -53,7 +53,7 @@ describe Spectator::Matchers::LessThanMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::LessThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(expected)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(expected)
end
it "is prefixed with <" do
@ -62,7 +62,7 @@ describe Spectator::Matchers::LessThanMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::LessThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should start_with("<")
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should start_with("<")
end
end
@ -73,7 +73,7 @@ describe Spectator::Matchers::LessThanMatcher do
partial = new_partial(actual)
matcher = Spectator::Matchers::LessThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(actual)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(actual)
end
context "when #matched? is true" do
@ -84,7 +84,7 @@ describe Spectator::Matchers::LessThanMatcher do
matcher = Spectator::Matchers::LessThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data.matched?.should be_true # Sanity check.
match_data_value_sans_prefix(match_data, :actual)[:to_s].should start_with("<")
match_data_value_sans_prefix(match_data.values, :actual)[:to_s].should start_with("<")
end
end
@ -96,7 +96,7 @@ describe Spectator::Matchers::LessThanMatcher do
matcher = Spectator::Matchers::LessThanMatcher.new(expected)
match_data = matcher.match(partial)
match_data.matched?.should be_false # Sanity check.
match_data_value_sans_prefix(match_data, :actual)[:to_s].should start_with(">=")
match_data_value_sans_prefix(match_data.values, :actual)[:to_s].should start_with(">=")
end
end
end

View file

@ -31,7 +31,7 @@ describe Spectator::Matchers::NilMatcher do
partial = new_partial(42)
matcher = Spectator::Matchers::NilMatcher.new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(nil)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(nil)
end
end
@ -41,7 +41,7 @@ describe Spectator::Matchers::NilMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::NilMatcher.new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(value)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value)
end
end
end

View file

@ -31,8 +31,8 @@ describe Spectator::Matchers::PredicateMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(empty: Nil, ascii_only: Nil)).new
match_data = matcher.match(partial)
match_data_has_key?(match_data, :empty).should be_true
match_data_has_key?(match_data, :ascii_only).should be_true
match_data_has_key?(match_data.values, :empty).should be_true
match_data_has_key?(match_data.values, :ascii_only).should be_true
end
it "has the actual values" do
@ -40,8 +40,8 @@ describe Spectator::Matchers::PredicateMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::PredicateMatcher(NamedTuple(empty: Nil, ascii_only: Nil)).new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :empty)[:value].should eq(value.empty?)
match_data_value_sans_prefix(match_data, :ascii_only)[:value].should eq(value.ascii_only?)
match_data_value_sans_prefix(match_data.values, :empty)[:value].should eq(value.empty?)
match_data_value_sans_prefix(match_data.values, :ascii_only)[:value].should eq(value.ascii_only?)
end
end

View file

@ -157,7 +157,7 @@ describe Spectator::Matchers::RangeMatcher do
partial = new_partial(5)
matcher = Spectator::Matchers::RangeMatcher.new(range)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :lower)[:value].should eq(range.begin)
match_data_value_sans_prefix(match_data.values, :lower)[:value].should eq(range.begin)
end
it "is prefixed with >=" do
@ -165,7 +165,7 @@ describe Spectator::Matchers::RangeMatcher do
partial = new_partial(5)
matcher = Spectator::Matchers::RangeMatcher.new(range)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :lower)[:to_s].should start_with(">=")
match_data_value_sans_prefix(match_data.values, :lower)[:to_s].should start_with(">=")
end
end
@ -175,7 +175,7 @@ describe Spectator::Matchers::RangeMatcher do
partial = new_partial(5)
matcher = Spectator::Matchers::RangeMatcher.new(range)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :upper)[:value].should eq(range.end)
match_data_value_sans_prefix(match_data.values, :upper)[:value].should eq(range.end)
end
context "when inclusive" do
@ -184,7 +184,7 @@ describe Spectator::Matchers::RangeMatcher do
partial = new_partial(5)
matcher = Spectator::Matchers::RangeMatcher.new(range)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :upper)[:to_s].should start_with("<=")
match_data_value_sans_prefix(match_data.values, :upper)[:to_s].should start_with("<=")
end
end
@ -194,7 +194,7 @@ describe Spectator::Matchers::RangeMatcher do
partial = new_partial(5)
matcher = Spectator::Matchers::RangeMatcher.new(range)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :upper)[:to_s].should start_with("<")
match_data_value_sans_prefix(match_data.values, :upper)[:to_s].should start_with("<")
end
end
end
@ -206,7 +206,7 @@ describe Spectator::Matchers::RangeMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(range)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(value)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value)
end
end
end
@ -219,7 +219,7 @@ describe Spectator::Matchers::RangeMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(array)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :set)[:value].should eq(array)
match_data_value_sans_prefix(match_data.values, :set)[:value].should eq(array)
end
end
@ -230,7 +230,7 @@ describe Spectator::Matchers::RangeMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(array)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(value)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value)
end
end
end

View file

@ -43,7 +43,7 @@ describe Spectator::Matchers::RegexMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(pattern)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(pattern)
end
end
@ -54,7 +54,7 @@ describe Spectator::Matchers::RegexMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(pattern)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(value)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value)
end
end
end

View file

@ -213,7 +213,7 @@ describe Spectator::Matchers::StartWithMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::StartWithMatcher.new(first)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(first)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(first)
end
end
@ -224,7 +224,7 @@ describe Spectator::Matchers::StartWithMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::StartWithMatcher.new(first)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(value)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value)
end
end
end
@ -237,7 +237,7 @@ describe Spectator::Matchers::StartWithMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::StartWithMatcher.new(first)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(first)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(first)
end
end
@ -248,7 +248,7 @@ describe Spectator::Matchers::StartWithMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::StartWithMatcher.new(first)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(array.first)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(array.first)
end
end
@ -259,7 +259,7 @@ describe Spectator::Matchers::StartWithMatcher do
partial = new_partial(array)
matcher = Spectator::Matchers::StartWithMatcher.new(first)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :list)[:value].should eq(array)
match_data_value_sans_prefix(match_data.values, :list)[:value].should eq(array)
end
end
end

View file

@ -58,7 +58,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(true)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should match(/false or nil/i)
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should match(/false or nil/i)
end
it "is prefixed with \"Not\"" do
@ -66,7 +66,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(true)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should start_with(/not/i)
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should start_with(/not/i)
end
end
@ -76,7 +76,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(true)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(value)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value)
end
end
@ -87,7 +87,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(true)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :truthy)[:value].should be_true
match_data_value_sans_prefix(match_data.values, :truthy)[:value].should be_true
end
end
@ -97,7 +97,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(true)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :truthy)[:value].should be_false
match_data_value_sans_prefix(match_data.values, :truthy)[:value].should be_false
end
end
@ -107,7 +107,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(true)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :truthy)[:value].should be_false
match_data_value_sans_prefix(match_data.values, :truthy)[:value].should be_false
end
end
end
@ -194,7 +194,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(false)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should match(/false or nil/i)
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should match(/false or nil/i)
end
it "is not prefixed with \"Not\"" do
@ -202,7 +202,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(false)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:to_s].should_not start_with(/not/i)
match_data_value_sans_prefix(match_data.values, :expected)[:to_s].should_not start_with(/not/i)
end
end
@ -212,7 +212,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(false)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(value)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value)
end
end
@ -223,7 +223,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(false)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :truthy)[:value].should be_true
match_data_value_sans_prefix(match_data.values, :truthy)[:value].should be_true
end
end
@ -233,7 +233,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(false)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :truthy)[:value].should be_false
match_data_value_sans_prefix(match_data.values, :truthy)[:value].should be_false
end
end
@ -243,7 +243,7 @@ describe Spectator::Matchers::TruthyMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TruthyMatcher.new(false)
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :truthy)[:value].should be_false
match_data_value_sans_prefix(match_data.values, :truthy)[:value].should be_false
end
end
end

View file

@ -62,7 +62,7 @@ describe Spectator::Matchers::TypeMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TypeMatcher(String).new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :expected)[:value].should eq(String)
match_data_value_sans_prefix(match_data.values, :expected)[:value].should eq(String)
end
end
@ -72,7 +72,7 @@ describe Spectator::Matchers::TypeMatcher do
partial = new_partial(value)
matcher = Spectator::Matchers::TypeMatcher(String).new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data, :actual)[:value].should eq(typeof(value))
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(typeof(value))
end
end
end

View file

@ -3,6 +3,9 @@ require "./match_data_value"
module Spectator::Matchers
# Wraps a value for used in match data.
private class GenericMatchDataValue(T) < MatchDataValue
# Underlying value.
getter value
# Creates the wrapper.
def initialize(@value : T)
end