2019-02-12 23:10:14 +00:00
|
|
|
# Formatter that doubles as a spy.
|
|
|
|
# This class tracks calls made to it.
|
2019-03-01 02:14:03 +00:00
|
|
|
class SpyFormatter < Spectator::Formatting::Formatter
|
2019-02-12 23:10:14 +00:00
|
|
|
{% for item in [
|
|
|
|
{"start_suite", "Spectator::TestSuite"},
|
|
|
|
{"start_example", "Spectator::Example"},
|
|
|
|
{"end_example", "Spectator::Result"},
|
|
|
|
] %}
|
|
|
|
{% method_name = item[0].id %}
|
|
|
|
{% argument_type = item[1].id %}
|
|
|
|
|
|
|
|
# Stores all invocations made to `#{{method_name}}`.
|
|
|
|
# Each element is an invocation and the value is the argument passed to the method.
|
|
|
|
getter {{method_name}}_calls = [] of {{argument_type}}
|
|
|
|
|
|
|
|
# Number of times the `#{{method_name}}` method was called.
|
|
|
|
def {{method_name}}_call_count
|
|
|
|
@{{method_name}}_calls.size
|
|
|
|
end
|
|
|
|
|
|
|
|
# Increments `#{{method_name}}_call_count` and stores the argument.
|
|
|
|
def {{method_name}}(arg : {{argument_type}})
|
|
|
|
@all_calls << {{method_name.symbolize}}
|
|
|
|
@{{method_name}}_calls << arg
|
|
|
|
end
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
2019-03-25 18:13:11 +00:00
|
|
|
# Stores all invocatiosn made to `#end_suite`.
|
|
|
|
# Each element is an invocation and the value is the arguments passed to the method.
|
|
|
|
getter end_suite_calls = [] of NamedTuple(report: Spectator::Report, profile: Bool)
|
|
|
|
|
|
|
|
# Number of times the `#end_suite` method was called.
|
|
|
|
def end_suite_call_count
|
|
|
|
@end_suite_calls.size
|
|
|
|
end
|
|
|
|
|
|
|
|
# Increments `#end_suite_call_count` and stores the arguments.
|
|
|
|
def end_suite(report, profile)
|
|
|
|
@all_calls << :end_suite
|
|
|
|
@end_suite_calls << {report: report, profile: profile}
|
|
|
|
end
|
|
|
|
|
2019-02-12 23:10:14 +00:00
|
|
|
# Stores the methods that were called and in which order.
|
|
|
|
# The symbols will be the method name (i.e. `:start_suite`).
|
|
|
|
getter all_calls = [] of Symbol
|
|
|
|
end
|