a work on process

This is the blog of James Stewart, a London-based web developer. You can find out more about my work on the Ket Lai site, follow me on twitter, or find me on github, flickr, last.fm or bkkeepr.

Cucumber, wordpress and database_cleaner

You are reading a post by James Stewart entitled Cucumber, wordpress and database_cleaner. It was posted on 7 August 2009 at 8:38 am.

You can find more posts by returning to the index.

Filed under: Notes, Snippets
Tagged: , , , , ,

I’m up to my usual using-ruby-tools-to-test-other-environments tricks, using cucumber and my wordpress activerecord classes to do acceptance testing against a highly-customised wordpress install.

I’m hoping to write a bit more about that soon, once I’ve put it through its paces a little more and cleaned up some of the code, but I wanted to quickly mention one of the key pain-points and an extremely handy solution.

One of the things I enjoy most about testing in rails is the handy tasks to prepare a blank database and the transactions that ensure the database is returned to that state after each test. Obviously that wasn’t going to work cleanly with wordpress since it doesn’t use ActiveRecord, but Matt kindly pointed me in the direction of Ben Mabey’s database_cleaner gem.

With that installed it’s as simple as adding:

require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = :truncation, {:except => %w[wp_options]}

to my

features/support/env.rb

file and my database is reset on each step. Combined with a few hooks to manage the configuration and load in the schema at the appropriate point, it’s turning into quite a nice little testing environment.

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Posts

 

No Comments

No comments yet.

Sorry, the comment form is closed at this time.