mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Adjust how Result#call works
This commit is contained in:
parent
8f85a6436f
commit
002c1d892b
5 changed files with 43 additions and 8 deletions
|
@ -6,9 +6,16 @@ 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.
|
# Calls the `error` method on *interface*.
|
||||||
def call(interface)
|
def call(interface)
|
||||||
interface.error(self)
|
interface.error
|
||||||
|
end
|
||||||
|
|
||||||
|
# Calls the `error` method on *interface*
|
||||||
|
# and passes the yielded value.
|
||||||
|
def call(interface)
|
||||||
|
value = yield self
|
||||||
|
interface.error(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,9 +16,16 @@ module Spectator
|
||||||
super(example, elapsed, expectations)
|
super(example, elapsed, expectations)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Calls the `failure` method on *interface* and passes self.
|
# Calls the `failure` method on *interface*.
|
||||||
def call(interface)
|
def call(interface)
|
||||||
interface.failure(self)
|
interface.failure
|
||||||
|
end
|
||||||
|
|
||||||
|
# Calls the `failure` method on *interface*
|
||||||
|
# and passes the yielded value.
|
||||||
|
def call(interface)
|
||||||
|
value = yield self
|
||||||
|
interface.failure(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,9 +5,16 @@ 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.
|
# Calls the `pending` method on *interface*.
|
||||||
def call(interface)
|
def call(interface)
|
||||||
interface.pending(self)
|
interface.pending
|
||||||
|
end
|
||||||
|
|
||||||
|
# Calls the `pending` method on *interface*
|
||||||
|
# and passes the yielded value.
|
||||||
|
def call(interface)
|
||||||
|
value = yield self
|
||||||
|
interface.pending(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,5 +15,12 @@ module Spectator
|
||||||
# This is used to avoid placing if or case-statements everywhere based on type.
|
# 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*.
|
# Each sub-class implements this method by calling the correct method on *interface*.
|
||||||
abstract def call(interface)
|
abstract def call(interface)
|
||||||
|
|
||||||
|
# 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*.
|
||||||
|
# This variation takes a block, which is passed the result.
|
||||||
|
# The value returned from the block will be returned by this method.
|
||||||
|
abstract def call(interface, &block : Result -> _)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,16 @@ require "./finished_result"
|
||||||
module Spectator
|
module Spectator
|
||||||
# Outcome that indicates running an example was successful.
|
# Outcome that indicates running an example was successful.
|
||||||
class SuccessfulResult < FinishedResult
|
class SuccessfulResult < FinishedResult
|
||||||
# Calls the `success` method on *interface* and passes self.
|
# Calls the `success` method on *interface*.
|
||||||
def call(interface)
|
def call(interface)
|
||||||
interface.success(self)
|
interface.success
|
||||||
|
end
|
||||||
|
|
||||||
|
# Calls the `success` method on *interface*
|
||||||
|
# and passes the yielded value.
|
||||||
|
def call(interface)
|
||||||
|
value = yield self
|
||||||
|
interface.success(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue