Reputation: 29689
Is there a Ruby Cucumber test hook for at_start
? I tried at_start and it didn't work.
I have something like this in support/hooks.rb
and I want to print a single global message before any of the tests start:
Before do
print '.'
end
at_exit do
puts ''
puts 'All Cucumber tests finished.'
end
It seems like if they have an at_exit
hook, they should have a before-start
hook as well right?
Upvotes: 0
Views: 878
Reputation: 26788
There is some documentation for "global hooks" at https://github.com/cucumber/cucumber/wiki/Hooks
You don't need to wrap it in any special method such as Before
or at_exit
. You just execute the code at the root level in any file contained in the features/support
directory, such as env.rb
. To copy and paste the example they've given:
# these following lines are executed at the root scope,
# accomplishing the same thing that an "at_start" block might.
my_heavy_object = HeavyObject.new
my_heavy_object.do_it
# other hooks can be defined in the same file
at_exit do
my_heavy_object.undo_it
end
They also give an example of how to write a Before
block that gets executed only once. Basically you have this block exit if some global variable is defined. The first time the block is run, the global variable is defined which prevents it from being executed multiple times. See the "Running a Before hook only once" section on that page I linked.
Upvotes: 2