mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add #call
method to each result
This feels like a good middle-ground. I didn't want this to be a factory method, or return an instance. That seemed like overkill for formatting. But I don't want to place if and case-statements everywhere in the formatters. I hope this doesn't violate single-responsibility principle or any other guidelines.
This commit is contained in:
parent
0b06e72f7e
commit
75f9a5838b
5 changed files with 23 additions and 0 deletions
|
@ -6,5 +6,9 @@ module Spectator
|
||||||
# This is different from a "failed" result
|
# This is different from a "failed" result
|
||||||
# in that the error was not from a failed expectation.
|
# in that the error was not from a failed expectation.
|
||||||
class ErroredResult < FailedResult
|
class ErroredResult < FailedResult
|
||||||
|
# Calls the `error` method on `interface` and passes `self`.
|
||||||
|
def call(interface)
|
||||||
|
interface.error(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,5 +18,10 @@ module Spectator
|
||||||
def initialize(example, elapsed, @expectations, @error)
|
def initialize(example, elapsed, @expectations, @error)
|
||||||
super(example, elapsed)
|
super(example, elapsed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Calls the `failure` method on `interface` and passes `self`.
|
||||||
|
def call(interface)
|
||||||
|
interface.failure(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,5 +5,9 @@ module Spectator
|
||||||
# A pending result means the example is not ready to run yet.
|
# A pending result means the example is not ready to run yet.
|
||||||
# This can happen when the functionality to be tested is not implemented yet.
|
# This can happen when the functionality to be tested is not implemented yet.
|
||||||
class PendingResult < Result
|
class PendingResult < Result
|
||||||
|
# Calls the `pending` method on `interface` and passes `self`.
|
||||||
|
def call(interface)
|
||||||
|
interface.pending(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,5 +10,10 @@ module Spectator
|
||||||
# and that this result is for.
|
# and that this result is for.
|
||||||
def initialize(@example)
|
def initialize(@example)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Calls the corresponding method for the type of result.
|
||||||
|
# This is used to avoid placing if or case-statements everywhere based on type.
|
||||||
|
# Each sub-class implements this method by calling the correct method on `interface`.
|
||||||
|
abstract def call(interface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,5 +14,10 @@ module Spectator
|
||||||
def initialize(example, elapsed, @expectations)
|
def initialize(example, elapsed, @expectations)
|
||||||
super(example, elapsed)
|
super(example, elapsed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Calls the `success` method on `interface` and passes `self`.
|
||||||
|
def call(interface)
|
||||||
|
interface.success(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue