From 1093571fbd0cdee822bb84e687716d5c9f08ecb6 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 4 Nov 2022 20:34:52 -0600 Subject: [PATCH] Add more info to stub.to_s --- src/spectator/mocks/exception_stub.cr | 6 ++++++ src/spectator/mocks/typed_stub.cr | 6 ++++++ src/spectator/mocks/value_stub.cr | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/src/spectator/mocks/exception_stub.cr b/src/spectator/mocks/exception_stub.cr index 9aee69c..e7b6cb9 100644 --- a/src/spectator/mocks/exception_stub.cr +++ b/src/spectator/mocks/exception_stub.cr @@ -20,6 +20,12 @@ module Spectator def initialize(method : Symbol, @exception : Exception, constraint : AbstractArguments? = nil, location : Location? = nil) super(method, constraint, location) end + + # String representation of the stub, formatted as a method call. + def to_s(io : IO) : Nil + super + io << " # raises " << @exception + end end module StubModifiers diff --git a/src/spectator/mocks/typed_stub.cr b/src/spectator/mocks/typed_stub.cr index 5067215..eabbcb9 100644 --- a/src/spectator/mocks/typed_stub.cr +++ b/src/spectator/mocks/typed_stub.cr @@ -9,5 +9,11 @@ module Spectator abstract class TypedStub(T) < Stub # Invokes the stubbed implementation. abstract def call(call : MethodCall) : T + + # String representation of the stub, formatted as a method call. + def to_s(io : IO) : Nil + super + io << " : " << T + end end end diff --git a/src/spectator/mocks/value_stub.cr b/src/spectator/mocks/value_stub.cr index 464c38b..7a84d19 100644 --- a/src/spectator/mocks/value_stub.cr +++ b/src/spectator/mocks/value_stub.cr @@ -20,6 +20,13 @@ module Spectator def initialize(method : Symbol, @value : T, constraint : AbstractArguments? = nil, location : Location? = nil) super(method, constraint, location) end + + # String representation of the stub, formatted as a method call and return value. + def to_s(io : IO) : Nil + super + io << " # => " + @value.inspect(io) + end end module StubModifiers