diff --git a/spec/helpers/matchers_helper.cr b/spec/helpers/matchers_helper.cr index 478ef84..e16ca66 100644 --- a/spec/helpers/matchers_helper.cr +++ b/spec/helpers/matchers_helper.cr @@ -1,16 +1,24 @@ -# Retrieves a value from the `NamedTuple` returned by `Spectator::Matchers::MatchData#values`. -def match_data_value(match_data, key) - match_data.values.fetch(key) { raise "#{key} is missing" } +# 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 } + raise "#{key} is missing" unless labeled_value + labeled_value.value end # Retrieves the string representation and base value -# from a `Spectator::Matchers::PrefixedMatchDataValue` -# in a `NamedTuple` returned by `Spectator::Matchers::MatchData#values`. -def match_data_prefix(match_data, key) - prefix = match_data.values.fetch(key) { raise "#{key} is missing" } +# 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 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 } + !!found +end diff --git a/spec/matchers/attributes_matcher_spec.cr b/spec/matchers/attributes_matcher_spec.cr index c22219c..b426496 100644 --- a/spec/matchers/attributes_matcher_spec.cr +++ b/spec/matchers/attributes_matcher_spec.cr @@ -249,10 +249,9 @@ describe Spectator::Matchers::AttributesMatcher do partial = new_partial(array) matcher = Spectator::Matchers::AttributesMatcher.new(attributes) match_data = matcher.match(partial) - values = match_data.values - values.has_key?(:"expected first").should be_true - values.has_key?(:"expected last").should be_true - values.has_key?(:"expected size").should be_true + 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 end it "contains a key for each actual value" do @@ -261,10 +260,9 @@ describe Spectator::Matchers::AttributesMatcher do partial = new_partial(array) matcher = Spectator::Matchers::AttributesMatcher.new(attributes) match_data = matcher.match(partial) - values = match_data.values - values.has_key?(:"actual first").should be_true - values.has_key?(:"actual last").should be_true - values.has_key?(:"actual size").should be_true + 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 end it "has the expected values" do @@ -273,10 +271,9 @@ describe Spectator::Matchers::AttributesMatcher do partial = new_partial(array) matcher = Spectator::Matchers::AttributesMatcher.new(attributes) match_data = matcher.match(partial) - values = match_data.values - values[:"expected first"].value.should eq(attributes[:first]) - values[:"expected last"].value.should eq(attributes[:last]) - values[:"expected size"].value.should eq(attributes[:size]) + 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]) end it "has the actual values" do @@ -285,10 +282,9 @@ describe Spectator::Matchers::AttributesMatcher do partial = new_partial(array) matcher = Spectator::Matchers::AttributesMatcher.new(attributes) match_data = matcher.match(partial) - values = match_data.values - values[:"actual first"].should eq(array.first) - values[:"actual last"].should eq(array.last) - values[:"actual size"].should eq(array.size) + 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) end end diff --git a/spec/matchers/case_matcher_spec.cr b/spec/matchers/case_matcher_spec.cr index 2c20d56..19c8f11 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.values[:expected].value.should eq(expected) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(actual) + match_data_value_sans_prefix(match_data, :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 5c074dc..f06a79a 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.values[:subset].value.should eq(search) + match_data_value_sans_prefix(match_data, :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.values[:superset].should eq(array) + match_data_value_sans_prefix(match_data, :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 2c54669..78984d9 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.values[:expected].value.size.should eq(0) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(array) + match_data_value_sans_prefix(match_data, :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 aa2e127..fcc821c 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.values[:expected].value.should eq(last) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(value) + match_data_value_sans_prefix(match_data, :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.values[:expected].should eq(last) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(array.last) + match_data_value_sans_prefix(match_data, :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.values[:list].should eq(array) + match_data_value_sans_prefix(match_data, :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 0745326..8b2b8c8 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.values[:expected].value.should eq(expected) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(actual) + match_data_value_sans_prefix(match_data, :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 2a7215e..9204d2c 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_prefix(match_data, :"expected type")[:value].should eq(KeyError) + match_data_value_sans_prefix(match_data, :"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_prefix(match_data, :"actual type")[:value].should eq(ArgumentError) + match_data_value_sans_prefix(match_data, :"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_prefix(match_data, :"actual type")[:value].should eq(Nil) + match_data_value_sans_prefix(match_data, :"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_prefix(match_data, :"expected message")[:value].should eq(regex) + match_data_value_sans_prefix(match_data, :"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_prefix(match_data, :"actual message")[:value].should eq(message) + match_data_value_sans_prefix(match_data, :"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 866cad8..df14fb6 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.values[:expected].value.should eq(expected) + match_data_value_sans_prefix(match_data, :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.values[:expected].to_s.should start_with(">=") + match_data_value_sans_prefix(match_data, :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.values[:actual].value.should eq(actual) + match_data_value_sans_prefix(match_data, :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.values[:actual].to_s.should start_with(">=") + match_data_value_sans_prefix(match_data, :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.values[:actual].to_s.should start_with("<") + match_data_value_sans_prefix(match_data, :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 604889b..9b15d74 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.values[:expected].value.should eq(expected) + match_data_value_sans_prefix(match_data, :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.values[:expected].to_s.should start_with(">") + match_data_value_sans_prefix(match_data, :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.values[:actual].value.should eq(actual) + match_data_value_sans_prefix(match_data, :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.values[:actual].to_s.should start_with(">") + match_data_value_sans_prefix(match_data, :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.values[:actual].to_s.should start_with("<=") + match_data_value_sans_prefix(match_data, :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 91affa7..8bd8a19 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.values[:key].value.should eq(key) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(tuple.keys) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(actual) + match_data_value_sans_prefix(match_data, :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 6a924b3..c65d4f4 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.values[:subset].value.should eq(search) + match_data_value_sans_prefix(match_data, :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.values[:superset].should eq(array) + match_data_value_sans_prefix(match_data, :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 13afe7f..5a37e5a 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.values[:value].value.should eq(value) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(hash.values) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(actual) + match_data_value_sans_prefix(match_data, :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 a4085ff..fdabfe1 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.values[:expected].value.should eq(expected) + match_data_value_sans_prefix(match_data, :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.values[:expected].to_s.should start_with("Not") + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(actual) + match_data_value_sans_prefix(match_data, :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 9a94f14..2cddf84 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.values[:expected].value.should eq(expected) + match_data_value_sans_prefix(match_data, :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.values[:expected].to_s.should start_with("<=") + match_data_value_sans_prefix(match_data, :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.values[:actual].value.should eq(actual) + match_data_value_sans_prefix(match_data, :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.values[:actual].to_s.should start_with("<=") + match_data_value_sans_prefix(match_data, :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.values[:actual].to_s.should start_with(">") + match_data_value_sans_prefix(match_data, :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 680bf43..a809632 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.values[:expected].value.should eq(expected) + match_data_value_sans_prefix(match_data, :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.values[:expected].to_s.should start_with("<") + match_data_value_sans_prefix(match_data, :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.values[:actual].value.should eq(actual) + match_data_value_sans_prefix(match_data, :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.values[:actual].to_s.should start_with("<") + match_data_value_sans_prefix(match_data, :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.values[:actual].to_s.should start_with(">=") + match_data_value_sans_prefix(match_data, :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 f1d1750..4455058 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.values[:expected].value.should eq(nil) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(value) + match_data_value_sans_prefix(match_data, :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 e71babc..083edc8 100644 --- a/spec/matchers/predicate_matcher_spec.cr +++ b/spec/matchers/predicate_matcher_spec.cr @@ -31,9 +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) - values = match_data.values - values.has_key?(:empty).should be_true - values.has_key?(:ascii_only).should be_true + match_data_has_key?(match_data, :empty).should be_true + match_data_has_key?(match_data, :ascii_only).should be_true end it "has the actual values" do @@ -41,9 +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) - values = match_data.values - values.[:empty].should eq(value.empty?) - values.[:ascii_only].should eq(value.ascii_only?) + 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?) end end diff --git a/spec/matchers/range_matcher_spec.cr b/spec/matchers/range_matcher_spec.cr index 7653c3a..8d9c50e 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_prefix(match_data, :lower)[:value].should eq(range.begin) + match_data_value_sans_prefix(match_data, :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_prefix(match_data, :lower)[:to_s].should start_with(">=") + match_data_value_sans_prefix(match_data, :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_prefix(match_data, :upper)[:value].should eq(range.end) + match_data_value_sans_prefix(match_data, :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_prefix(match_data, :upper)[:to_s].should start_with("<=") + match_data_value_sans_prefix(match_data, :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_prefix(match_data, :upper)[:to_s].should start_with("<") + match_data_value_sans_prefix(match_data, :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(match_data, :actual).should eq(value) + match_data_value_sans_prefix(match_data, :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_prefix(match_data, :set)[:value].should eq(array) + match_data_value_sans_prefix(match_data, :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(match_data, :actual).should eq(value) + match_data_value_sans_prefix(match_data, :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 f8bc94c..f8a9ef4 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.values[:expected].value.should eq(pattern) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(value) + match_data_value_sans_prefix(match_data, :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 cd10b0b..d35f491 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.values[:expected].value.should eq(first) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(value) + match_data_value_sans_prefix(match_data, :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.values[:expected].should eq(first) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(array.first) + match_data_value_sans_prefix(match_data, :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.values[:list].should eq(array) + match_data_value_sans_prefix(match_data, :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 8b636d8..21c0d24 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.values[:expected].to_s.should match(/false or nil/i) + match_data_value_sans_prefix(match_data, :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.values[:expected].to_s.should start_with(/not/i) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(value) + match_data_value_sans_prefix(match_data, :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.values[:truthy].should be_true + match_data_value_sans_prefix(match_data, :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.values[:truthy].should be_false + match_data_value_sans_prefix(match_data, :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.values[:truthy].should be_false + match_data_value_sans_prefix(match_data, :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.values[:expected].to_s.should match(/false or nil/i) + match_data_value_sans_prefix(match_data, :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.values[:expected].to_s.should_not start_with(/not/i) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(value) + match_data_value_sans_prefix(match_data, :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.values[:truthy].should be_true + match_data_value_sans_prefix(match_data, :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.values[:truthy].should be_false + match_data_value_sans_prefix(match_data, :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.values[:truthy].should be_false + match_data_value_sans_prefix(match_data, :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 962ac7c..e374563 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.values[:expected].value.should eq(String) + match_data_value_sans_prefix(match_data, :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.values[:actual].should eq(typeof(value)) + match_data_value_sans_prefix(match_data, :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 28f66b2..7e392ec 100644 --- a/src/spectator/matchers/generic_match_data_value.cr +++ b/src/spectator/matchers/generic_match_data_value.cr @@ -9,7 +9,7 @@ module Spectator::Matchers # Stringifies the value. def to_s(io) - io << value + io << @value end # Inspects the value.