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