From a585ef099656c96fd62ca70341f9e414387bf875 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 29 Nov 2022 20:28:15 -0700 Subject: [PATCH] Simplify string (inspect) representation These types make heavy use of generics and combined types. Instantiating string representation methods for all possibilities is unecesssary and slows down compilation. --- src/spectator/mocks/abstract_arguments.cr | 5 +++++ src/spectator/mocks/double.cr | 13 +++++++++++++ src/spectator/mocks/method_call.cr | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/spectator/mocks/abstract_arguments.cr b/src/spectator/mocks/abstract_arguments.cr index 810d2fe..b03f161 100644 --- a/src/spectator/mocks/abstract_arguments.cr +++ b/src/spectator/mocks/abstract_arguments.cr @@ -1,6 +1,11 @@ module Spectator # Untyped arguments to a method call (message). abstract class AbstractArguments + # Use the string representation to avoid over complicating debug output. + def inspect(io : IO) : Nil + to_s(io) + end + # Utility method for comparing two named tuples ignoring order. private def compare_named_tuples(a : NamedTuple, b : NamedTuple) a.each do |k, v1| diff --git a/src/spectator/mocks/double.cr b/src/spectator/mocks/double.cr index 8143ba0..ad7d327 100644 --- a/src/spectator/mocks/double.cr +++ b/src/spectator/mocks/double.cr @@ -101,6 +101,19 @@ module Spectator io << _spectator_stubbed_name end + # :ditto: + def inspect(io : IO) : Nil + {% if anno = @type.annotation(::Spectator::StubbedName) %} + io << "#' + end + # Defines a stub to change the behavior of a method in this double. # # NOTE: Defining a stub for a method not defined in the double's type has no effect. diff --git a/src/spectator/mocks/method_call.cr b/src/spectator/mocks/method_call.cr index b8e973e..9c5fd01 100644 --- a/src/spectator/mocks/method_call.cr +++ b/src/spectator/mocks/method_call.cr @@ -30,7 +30,13 @@ module Spectator # Constructs a string containing the method name and arguments. def to_s(io : IO) : Nil - io << '#' << method << arguments + io << '#' << method + arguments.inspect(io) + end + + # :ditto: + def inspect(io : IO) : Nil + to_s(io) end end end