Posted almost 10 years ago. Visible to the public. Repeats.

Cucumber pitfall: "Around" does not apply to your "Background" steps

Around will not happen until after a feature's Background has been processed. Use Before and After to avoid that.

Details

Consider this Cucumber feature file:

Copy
Feature: Something that needs to be tested Background: Given a user And I sign in Scenario: Sign out When I sign out Then I should see "Signed out" Scenario: Something else # ...

Now, assume you have these step definitions:

Copy
Around do puts "** Around: before yield" yield puts "** Around: after yield" end Before do puts "** Before" end

Running the above feature will give you (roughly) this Cucumber output:

Copy
** Before Given a user And I sign in ** Around: before yield When I sign out Then I should see "Signed out" ** Around: after yield

As you can see, your Around code did not happen until after Background was processed.

This can lead to serious trouble if you are not aware of that. For example: Using an Around step to switch things off will not switch them off until the Background steps have happened. If you do something like that, use Before and After steps instead.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Avatar
Arne Hartherz
Last edit:
over 4 years ago
by Dominik Schöler
Keywords:
order
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more