Adjust how Result#call works

This commit is contained in:
Michael Miller 2019-02-20 21:00:22 -07:00
parent 8f85a6436f
commit 002c1d892b
5 changed files with 43 additions and 8 deletions

View file

@ -6,9 +6,16 @@ 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.
# Calls the `error` method on *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

View file

@ -16,9 +16,16 @@ module Spectator
super(example, elapsed, expectations)
end
# Calls the `failure` method on *interface* and passes self.
# Calls the `failure` method on *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

View file

@ -5,9 +5,16 @@ 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.
# Calls the `pending` method on *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

View file

@ -15,5 +15,12 @@ module Spectator
# 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)
# 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

View file

@ -3,9 +3,16 @@ require "./finished_result"
module Spectator
# Outcome that indicates running an example was successful.
class SuccessfulResult < FinishedResult
# Calls the `success` method on *interface* and passes self.
# Calls the `success` method on *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