shard-spectator/spec/helpers/example_hooks_helper.cr

60 lines
1.7 KiB
Crystal
Raw Normal View History

# 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
2019-01-17 21:14:10 +00:00
# Creates a new `Spectator::ExampleConditions` instance.
# All arguments are optional,
# only specify the sets of conditions that are needed.
# The conditions that aren't specified will be left empty.
def new_conditions(
2019-01-23 21:46:15 +00:00
pre = [] of ->,
post = [] of ->
2019-01-17 21:14:10 +00:00
)
2019-01-23 21:46:15 +00:00
Spectator::ExampleConditions.new(pre, post)
2019-01-17 21:14:10 +00:00
end
# Creates a new `Spectator::ExampleConditions` instance.
# All arguments are optional,
# only specify a condition for the types that are needed.
# The conditions that aren't specified will be left empty.
def new_conditions(
2019-01-23 21:46:15 +00:00
pre : Proc(Nil)? = nil,
post : Proc(Nil)? = nil
2019-01-17 21:14:10 +00:00
)
new_conditions(
2019-01-23 21:46:15 +00:00
pre ? [pre] : [] of ->,
post ? [post] : [] of ->
2019-01-17 21:14:10 +00:00
)
end