Friendlier descriptions of objects

This commit is contained in:
Michael Miller 2019-10-13 18:49:22 -06:00
parent d422376aaf
commit 76fa7e294f
4 changed files with 22 additions and 1 deletions

View file

@ -6,6 +6,9 @@ module Spectator
@spectator_stubs = Deque(MethodStub).new
@spectator_stub_calls = Deque(MethodCall).new
def initialize(@spectator_double_name : Symbol)
end
private macro stub(definition, &block)
{%
name = nil
@ -78,6 +81,12 @@ module Spectator
end
end
def to_s(io)
io << "Double("
io << @spectator_double_name
io << ')'
end
protected def spectator_define_stub(stub : MethodStub) : Nil
@spectator_stubs << stub
end

View file

@ -9,6 +9,7 @@ module Spectator::DSL
{% else %}
class Double{{name.id}} < ::Spectator::Double
def initialize(@spectator_test : {{@type.id}})
super({{name.id.symbolize}})
end
forward_missing_to @spectator_test

View file

@ -9,5 +9,16 @@ module Spectator
def initialize(name : Symbol, @args : T, @options : NT)
super(name)
end
def to_s(io)
io << name
return if @args.empty? && @options.empty?
io << '('
io << @args
io << ", " if @args.any?
io << @options
io << ')'
end
end
end

View file

@ -17,7 +17,7 @@ module Spectator::Matchers
end
def failure_message(actual : TestExpression(T)) : String forall T
"#{actual.value} did not receive #{@expected.label}"
"#{actual.label} did not receive #{@expected.label}"
end
def values(actual : TestExpression(T)) forall T