Cannot change database_cleaner strategy between scenario #180

phuong-nguyen opened this Issue Oct 12, 2011 · 4 comments


None yet
2 participants

I want to use transaction strategy for Rack Test and truncation strategy for Selenium test but cucumber rails make it impossible by adding a Before hook that call DatabaseCleaner.start. I want to change the strategy before DatabaseCleaner.start called, but cannot figure it out, since all hooks are appended. This make our test much slower.


aslakhellesoy commented Oct 12, 2011

Did you try to define your own hooks before the built-in ones are defined?

# env.rb

Before('@javascript') do
   DatabaseCleaner.strategy = :truncation

After('@javascript') do
   DatabaseCleaner.strategy = DatabaseCleaner.default_strategy

# This defines the default hooks
require 'cucumber/rails'

Thanks for the tip. It works. But since DatabaseCleaner.default_strategy doesn't exist (anymore?), I replaced it with :transaction.

@aslakhellesoy aslakhellesoy reopened this Oct 14, 2011


aslakhellesoy commented Oct 14, 2011

I'm reopening this just so I remember to put better instructions in the generated files.


aslakhellesoy commented Nov 3, 2011

Obsolete by the fix of #166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment