Machinist and database_cleaner

Sat, 09.04.2011 machinist, database_cleaner

I run my cucumber features with the help of the spork server.
I have had some trouble getting my fixtures replacement Machinist to delete old objects in between iterations. In its present state, Machinist has a wonderful syntax, but a hassle: it drives itself nuts trying in order to achieve object caching, and so old objects persist in your test database after a test.

But I got the solution. You’ll need database_cleaner, and the following code at the end of your features/support/env.rb:

1
2
3
4
5
6
7
8
9
DatabaseCleaner.strategy = :truncation

Before do
  DatabaseCleaner.start
end

After do
  DatabaseCleaner.clean
end

It seems to me that the Machinist is going to solve this problem by dropping caching support all along in the near future, so this post might get soon outdated. I hope so, that was a nasty problem, almost invalidating the whole purpose of Machinist.

0 comments