Add documentation to ExampleConditions

This commit is contained in:
Michael Miller 2019-01-17 15:42:58 -07:00
parent db89a99562
commit ec9416285b

View file

@ -1,5 +1,13 @@
module Spectator module Spectator
# Collection of checks that run before and after tests.
# The pre-conditions can be used to verify
# that the SUT is in an expected state prior to testing.
# The post-conditions can be used to verify
# that the SUT is in an expected state after tests have finished.
# Each check is just a `Proc` (code block) that runs when invoked.
class ExampleConditions class ExampleConditions
# Creates an empty set of conditions.
# This will effectively run nothing extra while running a test.
def self.empty def self.empty
new( new(
[] of ->, [] of ->,
@ -7,16 +15,21 @@ module Spectator
) )
end end
# Creates a new set of conditions.
def initialize( def initialize(
@pre_conditions : Array(->), @pre_conditions : Array(->),
@post_conditions : Array(->) @post_conditions : Array(->)
) )
end end
# Runs all pre-condition checks.
# These should be run before every test.
def run_pre_conditions def run_pre_conditions
@pre_conditions.each &.call @pre_conditions.each &.call
end end
# Runs all post-condition checks.
# These should be run after every test.
def run_post_conditions def run_post_conditions
@post_conditions.each &.call @post_conditions.each &.call
end end