mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Use visitor pattern
This commit is contained in:
parent
d5c4d5e822
commit
a36982d6d6
1 changed files with 30 additions and 6 deletions
|
@ -24,13 +24,9 @@ module Spectator
|
||||||
# See `Formatting::Formatter#example_finished`
|
# See `Formatting::Formatter#example_finished`
|
||||||
private def example_finished(example)
|
private def example_finished(example)
|
||||||
notification = Formatting::ExampleNotification.new(example)
|
notification = Formatting::ExampleNotification.new(example)
|
||||||
|
visitor = ResultVisitor.new(formatter, notification)
|
||||||
formatter.example_started(notification)
|
formatter.example_started(notification)
|
||||||
|
example.result.accept(visitor)
|
||||||
case example.result
|
|
||||||
when .fail? then formatter.example_failed(notification)
|
|
||||||
when .pass? then formatter.example_passed(notification)
|
|
||||||
else formatter.example_pending(notification)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Triggers the 'stop' event.
|
# Triggers the 'stop' event.
|
||||||
|
@ -44,6 +40,34 @@ module Spectator
|
||||||
private def close
|
private def close
|
||||||
formatter.close(nil)
|
formatter.close(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Provides methods for the various result types.
|
||||||
|
private struct ResultVisitor
|
||||||
|
# Creates the visitor.
|
||||||
|
# Requires the *formatter* to notify and the *notification* to send it.
|
||||||
|
def initialize(@formatter : Formatting::Formatter, @notification : Formatting::ExampleNotification)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Invokes the example passed method.
|
||||||
|
def pass
|
||||||
|
@formatter.example_passed(@notification)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Invokes the example failed method.
|
||||||
|
def fail
|
||||||
|
@formatter.example_failed(@notification)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Invokes the example failed method.
|
||||||
|
def error
|
||||||
|
@formatter.example_failed(@notification)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Invokes the example pending method.
|
||||||
|
def pending
|
||||||
|
@formatter.example_pending(@notification)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue