From c68cd7e16a7761a0484c109ab22680ab34e71769 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 20 Nov 2018 14:51:11 -0700 Subject: [PATCH] Move example hooks helper methods to their own file --- spec/example_hooks_spec.cr | 27 ---------------------- spec/helpers/example_hooks_helper.cr | 34 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 spec/helpers/example_hooks_helper.cr diff --git a/spec/example_hooks_spec.cr b/spec/example_hooks_spec.cr index 2b486b1..a15e333 100644 --- a/spec/example_hooks_spec.cr +++ b/spec/example_hooks_spec.cr @@ -1,32 +1,5 @@ require "./spec_helper" -def new_hooks( - before_all = [] of ->, - before_each = [] of ->, - after_all = [] of ->, - after_each = [] of ->, - around_each = [] of Proc(Nil) -> -) - Spectator::ExampleHooks.new(before_all, before_each, - after_all, after_each, around_each) -end - -def new_hooks( - before_all : Proc(Nil)? = nil, - before_each : Proc(Nil)? = nil, - after_all : Proc(Nil)? = nil, - after_each : Proc(Nil)? = nil, - around_each : Proc(Proc(Nil), Nil)? = nil -) - new_hooks( - before_all ? [before_all] : [] of ->, - before_each ? [before_each] : [] of ->, - after_all ? [after_all] : [] of ->, - after_each ? [after_each] : [] of ->, - around_each ? [around_each] : [] of Proc(Nil) -> - ) -end - describe Spectator::ExampleHooks do {% for hook in %i[before_all before_each after_all after_each] %} describe "#run_{{hook.id}}" do diff --git a/spec/helpers/example_hooks_helper.cr b/spec/helpers/example_hooks_helper.cr new file mode 100644 index 0000000..dce5caa --- /dev/null +++ b/spec/helpers/example_hooks_helper.cr @@ -0,0 +1,34 @@ +# Creates a new `Spectator::ExampleHooks` instance. +# All arguments are optional, +# only specify the sets of hooks that are needed. +# The hooks that aren't specified will be left empty. +def new_hooks( + before_all = [] of ->, + before_each = [] of ->, + after_all = [] of ->, + after_each = [] of ->, + around_each = [] of Proc(Nil) -> +) + Spectator::ExampleHooks.new(before_all, before_each, + after_all, after_each, around_each) +end + +# Creates a new `Spectator::ExampleHooks` instance. +# All arguments are optional, +# only specify a hook for the types that are needed. +# The hooks that aren't specified will be left empty. +def new_hooks( + before_all : Proc(Nil)? = nil, + before_each : Proc(Nil)? = nil, + after_all : Proc(Nil)? = nil, + after_each : Proc(Nil)? = nil, + around_each : Proc(Proc(Nil), Nil)? = nil +) + new_hooks( + before_all ? [before_all] : [] of ->, + before_each ? [before_each] : [] of ->, + after_all ? [after_all] : [] of ->, + after_each ? [after_each] : [] of ->, + around_each ? [around_each] : [] of Proc(Nil) -> + ) +end