diff --git a/src/spectator/example_group_hook.cr b/src/spectator/example_group_hook.cr index 11b0117..06b8c7d 100644 --- a/src/spectator/example_group_hook.cr +++ b/src/spectator/example_group_hook.cr @@ -1,9 +1,8 @@ -require "./context_delegate" require "./label" require "./source" module Spectator - # Information about a hook tied to an example group and a delegate to invoke it. + # Information about a hook tied to an example group and a proc to invoke it. class ExampleGroupHook # Location of the hook in source code. getter! source : Source @@ -11,22 +10,24 @@ module Spectator # User-defined description of the hook. getter! label : Label - # Creates the hook with a context delegate. - # The *delegate* will be called when the hook is invoked. + @proc : -> + + # Creates the hook with a proc. + # The *proc* will be called when the hook is invoked. # A *source* and *label* can be provided for debugging. - def initialize(@delegate : ContextDelegate, *, @source : Source? = nil, @label : Label = nil) + def initialize(@proc : (->), *, @source : Source? = nil, @label : Label = nil) end # Creates the hook with a block. # The block will be executed when the hook is invoked. # A *source* and *label* can be provided for debugging. def initialize(*, @source : Source? = nil, @label : Label = nil, &block : -> _) - @delegate = ContextDelegate.null(&block) + @proc = block end # Invokes the hook. def call : Nil - @delegate.call + @proc.call end # Produces the string representation of the hook. diff --git a/src/spectator/example_hook.cr b/src/spectator/example_hook.cr index 4597981..b61fa7d 100644 --- a/src/spectator/example_hook.cr +++ b/src/spectator/example_hook.cr @@ -1,9 +1,8 @@ -require "./example_context_delegate" require "./label" require "./source" module Spectator - # Information about a hook tied to an example and a delegate to invoke it. + # Information about a hook tied to an example and a proc to invoke it. class ExampleHook # Location of the hook in source code. getter! source : Source @@ -11,10 +10,12 @@ module Spectator # User-defined description of the hook. getter! label : Label - # Creates the hook with an example context delegate. - # The *delegate* will be called when the hook is invoked. + @proc : Example -> + + # Creates the hook with a proc. + # The *proc* will be called when the hook is invoked. # A *source* and *label* can be provided for debugging. - def initialize(@delegate : ExampleContextDelegate, *, @source : Source? = nil, @label : Label = nil) + def initialize(@proc : (Example ->), *, @source : Source? = nil, @label : Label = nil) end # Creates the hook with a block. @@ -22,13 +23,13 @@ module Spectator # The block will be executed when the hook is invoked. # A *source* and *label* can be provided for debugging. def initialize(*, @source : Source? = nil, @label : Label = nil, &block : Example -> _) - @delegate = ExampleContextDelegate.null(&block) + @proc = block end # Invokes the hook. # The *example* refers to the current example. def call(example : Example) : Nil - @delegate.call(example) + @proc.call(example) end # Produces the string representation of the hook.