Add more info to stub.to_s

This commit is contained in:
Michael Miller 2022-11-04 20:34:52 -06:00
parent c00d2fe4e6
commit 1093571fbd
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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