Posted about 1 month ago. Visible to the public.

Ruby: A short summary of available hooks in Cucumber

Here is a short summary of Cucumber hooks in Ruby taken from https://github.com/cucumber/cucumber-ruby. Note that the BeforeStep is currently not existing in the Ruby implementation of Cucumber.

Before hooks run before the first step of each scenario.

Copy
Before do |scenario| ... end

After hooks run after the last step of each scenario, even when the step result is failed, undefined, pending or skipped.

Copy
After do |scenario| ... end
Copy
Around do |scenario, block| ... block.call ... end
Copy
AfterStep do |scenario| ... end

You can restrict the hooks to one or more tags:

Copy
Before("@slow") do |scenario| ... end

A global hook will run once before any scenario is run.

Copy
# env.rb ...

AfterConfiguration hooks will run only once after support has been loaded, and before any features are loaded.

Copy
AfterConfiguration do |config| ... end

You can include code to Cucumber in the World module without polluting the application namespace (example from https://jam.cucumber.io/):

features/support/helpers.rb

Copy
module Helpers def helper_method 42 end end World(Helpers)

features/step_definitions/step.rb

Copy
Then /^the helper method is called$/ do expect(helper_method).to eql(42) end

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Emanuel De
Last edit:
about 1 month ago
by Julian
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more