Last Updated: February 25, 2016
·
696
· descentintomael

Cucumber's before block

In order to get a step to run before every scenario regardless of whether its specified, use this format:

Given /^(?:no users)$/ do
  User.delete_all
end

As you can see in that example, I use this mainly for database setup to ensure constancy.

The key to this is to put everything in a non-capturing group. This then ends up matching everything.

Credit goes to the wonderful email-spec