Quantcast
Channel: blog.andrewbruce.net » Rails
Viewing all articles
Browse latest Browse all 9

CruiseControl.rb rake task for running rspec and cucumber with a single test database

$
0
0

I wrote this rake task for running the rspec and cucumber tests for a Rails app whilst ensuring that only one database is used. It took a bit of Googling and lots of trial and error so thought I’d share it.

The main stumbling block for running the standard rspec and cucumber tasks is the prerequisite step db:test:prepare. This task that is performed before both ‘rake spec’ and ‘rake cucumber:ok’ assumes there is a development database available from which to clone the test database. Since I wanted to test the app on a Continuous Integration server, I didn’t want to clone another database, but decided to use the checked-in schema.rb file. This approach entails that your migrations won’t be run as part of your CI. However, for my purposes I’m happy to test migrations on the staging server, which has some close-to-live data anyway. Since migrations always have the potential to affect data it seemed superfluous to test them with Cruise.

Whilst writing this I nearly bottled it and ran separate ruby instances inside backticks. I realised I’d done this in the past, so decided to go the whole hog and fix this for real. I hope it saves you some time!

Stick the following into e.g. lib/tasks/cruise.rb. CruiseControl.rb first tries to run the ‘cruise’ task before the default rake task. This is handy for us as we want to change the database config to use an RDS test database (on our dev machines we use local databases).


Viewing all articles
Browse latest Browse all 9

Trending Articles