shard-spectator/spec/helpers/spy_sut.cr

28 lines
591 B
Crystal
Raw Normal View History

# Example system to test that doubles as a spy.
# This class tracks calls made to it.
class SpySUT
{% for item in [
{"==", "eq"},
{"!=", "ne"},
{"<", "lt"},
{"<=", "le"},
{">", "gt"},
{">=", "ge"},
{"===", "case_eq"},
{"=~", "match"}
] %}
{% operator = item[0].id %}
{% name = item[1].id %}
# Number of times the `#{{operator}}` method was called.
getter {{name}}_call_count = 0
2019-01-19 20:50:57 +00:00
# Returns true and increments `#{{name}}_call_count`.
def {{operator}}(other : T) forall T
@{{name}}_call_count += 1
2019-01-19 20:50:57 +00:00
true
end
2019-01-19 21:49:13 +00:00
{% end %}
end