shard-spectator/spec/helpers/spy_sut.cr

29 lines
764 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 [
2019-01-24 04:11:01 +00:00
{"==", "eq"},
{"!=", "ne"},
{"<", "lt"},
{"<=", "le"},
{">", "gt"},
{">=", "ge"},
{"===", "case_eq"},
{"=~", "match"},
2019-01-25 20:12:34 +00:00
{"includes?", "includes"},
2019-01-24 04:11:01 +00:00
] %}
{% 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