DatabaseCleaner in cucumber-rails sets strategy = :truncation

374 views
Skip to first unread message

Constantin Gavrilescu

unread,
Apr 4, 2011, 5:24:43 PM4/4/11
to Cukes
I upgraded from cucumber-rails-0.3.x to cucumber-rails-0.4.0 and my
features broke. Truncation doesn't work on my database setup. Some new
code was changing my DatabaseCleaner.strategy from :transaction
to :truncation.

I finally found it in:
cucumber-rails-0.4.0/lib/cucumber/rails/hooks/database_cleaner.rb:15
14 Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity',
'~@javascript') do
15 DatabaseCleaner.strategy = :truncation
16 end

What's the motivation for this code?
I don't have any tags on my scenarios, and it seems to run when you
don't.

Julien Biezemans

unread,
Apr 4, 2011, 6:43:29 PM4/4/11
to cu...@googlegroups.com
Hi Constantin,

When running cucumber with backends like selenium or culerity, there
are two processes involved: one for your application (server) and
another one for cucumber. It means there are two different MySQL
connections: one in each process. SQL transactions are bound to
database connections; it means cucumber cannot rollback a transaction
initiated by your app's server.

HTH,

Julien.

> --
> You received this message because you are subscribed to the Google Groups "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
>
>

--
Julien Biezemans - j...@jbpros.com
JBpro's Interactive - http://www.jbpros.com/
+32 495 60 32 79

aslak hellesoy

unread,
Apr 4, 2011, 6:48:36 PM4/4/11
to cu...@googlegroups.com, Constantin Gavrilescu
On Mon, Apr 4, 2011 at 10:24 PM, Constantin Gavrilescu
<comisaru...@gmail.com> wrote:
> I upgraded from cucumber-rails-0.3.x to cucumber-rails-0.4.0 and my
> features broke. Truncation doesn't work on my database setup. Some new
> code was changing my DatabaseCleaner.strategy from :transaction
> to :truncation.
>
> I finally found it in:
> cucumber-rails-0.4.0/lib/cucumber/rails/hooks/database_cleaner.rb:15
>  14   Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity',
> '~@javascript') do
>  15     DatabaseCleaner.strategy = :truncation
>  16   end
>
> What's the motivation for this code?

It's a bug: https://github.com/aslakhellesoy/cucumber-rails/pull/113

Should be fixed in the next release.

Aslak

> I don't have any tags on my scenarios, and it seems to run when you
> don't.
>

Constantin Gavrilescu

unread,
Apr 5, 2011, 6:58:41 AM4/5/11
to Cukes


On Apr 4, 5:48 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> On Mon, Apr 4, 2011 at 10:24 PM, Constantin Gavrilescu
>
> <comisarulmoldo...@gmail.com> wrote:

> > cucumber-rails-0.4.0/lib/cucumber/rails/hooks/database_cleaner.rb:15
> >  14   Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity',
> > '~@javascript') do
> >  15     DatabaseCleaner.strategy = :truncation
> >  16   end
>
> > What's the motivation for this code?
>
> It's a bug:https://github.com/aslakhellesoy/cucumber-rails/pull/113
>
> Should be fixed in the next release.

In the hooks/database_cleaner.rb the first two lines are these
comments:
1 # Default setup for DatabaseCleaner that will work for most
projects.
2 # If you need your own setup, roll your own.

I really want to "roll my own" until that bug is fixed or for good.
However, the comment tells me that I can roll my own, but not how. How
one would override the code in hooks/*?

Constantin Gavrilescu

unread,
Apr 5, 2011, 7:19:46 AM4/5/11
to Cukes
On Apr 4, 5:48 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:

> It's a bug:https://github.com/aslakhellesoy/cucumber-rails/pull/113
>
> Should be fixed in the next release.

http://rubygems.org/gems/cucumber-rails
# 0.4.1 April 4, 2011
Wow!
Thank you, Aslak for releasing the new version!

aslak hellesoy

unread,
Apr 5, 2011, 7:54:28 AM4/5/11
to cu...@googlegroups.com, Constantin Gavrilescu

You're welcome - hope this works for you

tsdbrown

unread,
Apr 21, 2011, 6:20:41 AM4/21/11
to Cukes
Would it possible to pass options to the DatabaseCleaner.strategy
= :trunaction call inside the database_cleaner.rb hook? I've placed a
copy of the setup into the local support dir for now to override it
for the @javascript tag before block, I needed to add the :except =>
[tables_here] as option and couldn't work out a nicer way to do it.

On Apr 5, 12:54 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> On Tue, Apr 5, 2011 at 12:19 PM, Constantin Gavrilescu
>

aslak hellesoy

unread,
Apr 21, 2011, 10:46:33 AM4/21/11
to cu...@googlegroups.com
On Thu, Apr 21, 2011 at 11:20 AM, tsdbrown <tsdb...@gmail.com> wrote:
Would it possible to pass options to the DatabaseCleaner.strategy
= :trunaction call inside the database_cleaner.rb hook? I've placed a
copy of the setup into the local support dir for now to override it
for the @javascript tag before block, I needed to add the :except =>
[tables_here] as option and couldn't work out a nicer way to do it.


Yeah maybe. Care to send a pull request if you find something that works?

tsdbrown

unread,
Apr 22, 2011, 3:31:31 PM4/22/11
to Cukes
Haha, I figured I might receive such a response. I'll see what I can
come up with. What is the thinking on the pull request to remove the
defaults?


On Apr 21, 3:46 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages