diff --git a/spec/helpers/matchers_helper.cr b/spec/helpers/matchers_helper.cr index e16ca66..2f123df 100644 --- a/spec/helpers/matchers_helper.cr +++ b/spec/helpers/matchers_helper.cr @@ -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 diff --git a/spec/matchers/attributes_matcher_spec.cr b/spec/matchers/attributes_matcher_spec.cr index b426496..36bedc5 100644 --- a/spec/matchers/attributes_matcher_spec.cr +++ b/spec/matchers/attributes_matcher_spec.cr @@ -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 diff --git a/spec/matchers/case_matcher_spec.cr b/spec/matchers/case_matcher_spec.cr index 19c8f11..cf4d442 100644 --- a/spec/matchers/case_matcher_spec.cr +++ b/spec/matchers/case_matcher_spec.cr @@ -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 diff --git a/spec/matchers/contain_matcher_spec.cr b/spec/matchers/contain_matcher_spec.cr index f06a79a..a10af48 100644 --- a/spec/matchers/contain_matcher_spec.cr +++ b/spec/matchers/contain_matcher_spec.cr @@ -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 diff --git a/spec/matchers/empty_matcher_spec.cr b/spec/matchers/empty_matcher_spec.cr index 78984d9..eea43bc 100644 --- a/spec/matchers/empty_matcher_spec.cr +++ b/spec/matchers/empty_matcher_spec.cr @@ -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 diff --git a/spec/matchers/end_with_matcher_spec.cr b/spec/matchers/end_with_matcher_spec.cr index fcc821c..d9894d5 100644 --- a/spec/matchers/end_with_matcher_spec.cr +++ b/spec/matchers/end_with_matcher_spec.cr @@ -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 diff --git a/spec/matchers/equality_matcher_spec.cr b/spec/matchers/equality_matcher_spec.cr index 8b2b8c8..b997a0f 100644 --- a/spec/matchers/equality_matcher_spec.cr +++ b/spec/matchers/equality_matcher_spec.cr @@ -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 diff --git a/spec/matchers/exception_matcher_spec.cr b/spec/matchers/exception_matcher_spec.cr index 9204d2c..b5c31b4 100644 --- a/spec/matchers/exception_matcher_spec.cr +++ b/spec/matchers/exception_matcher_spec.cr @@ -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 diff --git a/spec/matchers/greater_than_equal_matcher_spec.cr b/spec/matchers/greater_than_equal_matcher_spec.cr index df14fb6..cc1c6a3 100644 --- a/spec/matchers/greater_than_equal_matcher_spec.cr +++ b/spec/matchers/greater_than_equal_matcher_spec.cr @@ -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 diff --git a/spec/matchers/greater_than_matcher_spec.cr b/spec/matchers/greater_than_matcher_spec.cr index 9b15d74..bcd2a57 100644 --- a/spec/matchers/greater_than_matcher_spec.cr +++ b/spec/matchers/greater_than_matcher_spec.cr @@ -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 diff --git a/spec/matchers/have_key_matcher_spec.cr b/spec/matchers/have_key_matcher_spec.cr index 8bd8a19..cbcf6f6 100644 --- a/spec/matchers/have_key_matcher_spec.cr +++ b/spec/matchers/have_key_matcher_spec.cr @@ -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 diff --git a/spec/matchers/have_matcher_spec.cr b/spec/matchers/have_matcher_spec.cr index c65d4f4..f4e917f 100644 --- a/spec/matchers/have_matcher_spec.cr +++ b/spec/matchers/have_matcher_spec.cr @@ -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 diff --git a/spec/matchers/have_value_matcher_spec.cr b/spec/matchers/have_value_matcher_spec.cr index 5a37e5a..78ba281 100644 --- a/spec/matchers/have_value_matcher_spec.cr +++ b/spec/matchers/have_value_matcher_spec.cr @@ -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 diff --git a/spec/matchers/inequality_matcher_spec.cr b/spec/matchers/inequality_matcher_spec.cr index fdabfe1..1dcdcfc 100644 --- a/spec/matchers/inequality_matcher_spec.cr +++ b/spec/matchers/inequality_matcher_spec.cr @@ -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 diff --git a/spec/matchers/less_than_equal_matcher_spec.cr b/spec/matchers/less_than_equal_matcher_spec.cr index 2cddf84..d6fd825 100644 --- a/spec/matchers/less_than_equal_matcher_spec.cr +++ b/spec/matchers/less_than_equal_matcher_spec.cr @@ -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 diff --git a/spec/matchers/less_than_matcher_spec.cr b/spec/matchers/less_than_matcher_spec.cr index a809632..695d55a 100644 --- a/spec/matchers/less_than_matcher_spec.cr +++ b/spec/matchers/less_than_matcher_spec.cr @@ -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 diff --git a/spec/matchers/nil_matcher_spec.cr b/spec/matchers/nil_matcher_spec.cr index 4455058..3250d02 100644 --- a/spec/matchers/nil_matcher_spec.cr +++ b/spec/matchers/nil_matcher_spec.cr @@ -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 diff --git a/spec/matchers/predicate_matcher_spec.cr b/spec/matchers/predicate_matcher_spec.cr index 083edc8..5a9b2c2 100644 --- a/spec/matchers/predicate_matcher_spec.cr +++ b/spec/matchers/predicate_matcher_spec.cr @@ -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 diff --git a/spec/matchers/range_matcher_spec.cr b/spec/matchers/range_matcher_spec.cr index 8d9c50e..71ffa15 100644 --- a/spec/matchers/range_matcher_spec.cr +++ b/spec/matchers/range_matcher_spec.cr @@ -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 diff --git a/spec/matchers/regex_matcher_spec.cr b/spec/matchers/regex_matcher_spec.cr index f8a9ef4..295b9a7 100644 --- a/spec/matchers/regex_matcher_spec.cr +++ b/spec/matchers/regex_matcher_spec.cr @@ -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 diff --git a/spec/matchers/start_with_matcher_spec.cr b/spec/matchers/start_with_matcher_spec.cr index d35f491..de626a5 100644 --- a/spec/matchers/start_with_matcher_spec.cr +++ b/spec/matchers/start_with_matcher_spec.cr @@ -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 diff --git a/spec/matchers/truthy_matcher_spec.cr b/spec/matchers/truthy_matcher_spec.cr index 21c0d24..91acae9 100644 --- a/spec/matchers/truthy_matcher_spec.cr +++ b/spec/matchers/truthy_matcher_spec.cr @@ -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 diff --git a/spec/matchers/type_matcher_spec.cr b/spec/matchers/type_matcher_spec.cr index e374563..81a430b 100644 --- a/spec/matchers/type_matcher_spec.cr +++ b/spec/matchers/type_matcher_spec.cr @@ -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 diff --git a/src/spectator/matchers/generic_match_data_value.cr b/src/spectator/matchers/generic_match_data_value.cr index 7e392ec..3d751f9 100644 --- a/src/spectator/matchers/generic_match_data_value.cr +++ b/src/spectator/matchers/generic_match_data_value.cr @@ -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