diff --git a/src/spectator/errored_result.cr b/src/spectator/errored_result.cr index 15db072..0736782 100644 --- a/src/spectator/errored_result.cr +++ b/src/spectator/errored_result.cr @@ -6,5 +6,9 @@ module Spectator # This is different from a "failed" result # in that the error was not from a failed expectation. class ErroredResult < FailedResult + # Calls the `error` method on `interface` and passes `self`. + def call(interface) + interface.error(self) + end end end diff --git a/src/spectator/failed_result.cr b/src/spectator/failed_result.cr index c26c57e..6e70751 100644 --- a/src/spectator/failed_result.cr +++ b/src/spectator/failed_result.cr @@ -18,5 +18,10 @@ module Spectator def initialize(example, elapsed, @expectations, @error) super(example, elapsed) end + + # Calls the `failure` method on `interface` and passes `self`. + def call(interface) + interface.failure(self) + end end end diff --git a/src/spectator/pending_result.cr b/src/spectator/pending_result.cr index 674a960..b00d05c 100644 --- a/src/spectator/pending_result.cr +++ b/src/spectator/pending_result.cr @@ -5,5 +5,9 @@ module Spectator # 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. class PendingResult < Result + # Calls the `pending` method on `interface` and passes `self`. + def call(interface) + interface.pending(self) + end end end diff --git a/src/spectator/result.cr b/src/spectator/result.cr index b2933cd..ec438a3 100644 --- a/src/spectator/result.cr +++ b/src/spectator/result.cr @@ -10,5 +10,10 @@ module Spectator # and that this result is for. def initialize(@example) 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 diff --git a/src/spectator/successful_result.cr b/src/spectator/successful_result.cr index 8bae742..aabeadb 100644 --- a/src/spectator/successful_result.cr +++ b/src/spectator/successful_result.cr @@ -14,5 +14,10 @@ module Spectator def initialize(example, elapsed, @expectations) super(example, elapsed) end + + # Calls the `success` method on `interface` and passes `self`. + def call(interface) + interface.success(self) + end end end