diff --git a/spec/expectations/expectation_spec.cr b/spec/expectations/expectation_spec.cr index e00a72e..8bd0a8d 100644 --- a/spec/expectations/expectation_spec.cr +++ b/spec/expectations/expectation_spec.cr @@ -41,6 +41,15 @@ describe Spectator::Expectations::Expectation do end end + describe "#values" do + it "is the same as the match data values" do + value = 42 + match_data = new_matcher(value).match(new_partial(value)) + expectation = Spectator::Expectations::Expectation.new(match_data, false) + expectation.values.should eq(match_data.values) + end + end + describe "#actual_message" do context "with a successful match" do it "equals the matcher's #message" do diff --git a/src/spectator/expectations/expectation.cr b/src/spectator/expectations/expectation.cr index 9a37858..c53a5f9 100644 --- a/src/spectator/expectations/expectation.cr +++ b/src/spectator/expectations/expectation.cr @@ -18,6 +18,12 @@ module Spectator::Expectations @match_data.matched? ^ @negated end + # Information about the match. + # Returned value and type will something that has key-value pairs (like a `NamedTuple`). + def values + @match_data.values + end + # Text that indicates the condition that must be met for the expectation to be satisifed. def expected_message @negated ? @match_data.negated_message : @match_data.message diff --git a/src/spectator/formatters/failure_block.cr b/src/spectator/formatters/failure_block.cr index 3575195..f976d89 100644 --- a/src/spectator/formatters/failure_block.cr +++ b/src/spectator/formatters/failure_block.cr @@ -61,8 +61,15 @@ module Spectator::Formatters private def values(io) io.puts indent do - line(io) { io << "Expected: TODO" } - line(io) { io << " got: TODO" } + @result.expectations.each_unsatisfied do |expectation| + expectation.values.each do |key, value| + line(io) do + io << key + io << ": " + io << value + end + end + end end io.puts end