If you are serious about agile software development you should use continuous integration. Over there in the Java world are plenty of professional tools available to do this job. Here in the Ruby/Rails world we are suffering from a little shortcoming of those tools. Of course you can always use CruiseControl for doing the job, but some tool aware of the specific settings in a Ruby/Rails environment would be nice.
And guess what, somebody thought just the same and through such a tool right out there as an OpenSource tool: CruiseControl.rb. This great tool is maintained by the guys from ThoughtWorks Studios and provides a very simple approach to CI. It is implemented in Rails, comes with some nice plug-ins for build notification and has a convenient web-interface.
There is only one thing, I was struggling with quite a while: The tasks CruiseControl.rb runs to build your project. I know this sounds really simple and it surely is, but as I had some problems I want to share my experience. First of all CruiseControl.rb looks for a tasks named cruise in your projects Rakefile. If there is no such tasks it will look for the default task, which is in your everyday Rails project the test tasks. If you are not using vanilla testing alone but enhanced it by some test/spec testing you cannot solely use the default tasks, but you have to run an adapted test tasks. It seems kind of rational not to overwrite your test tasks, but to provide your own tasks for running the BDD test cases. And if this is not enough imagine your tests rely on a running memcached server (which some people say is a bad idea). Given all that we come to a point where leaving CruiseControl.rb guessing the right tasks to build our project isn’t a good idea anymore.
The result is the following (simple) custom tasks:
desc "Task to run all required tasks to perform continuos integration with CruiseControl.rb."
task :cruise => "db:migrate" do
Rake::Task["db:test:purge"].invoke
Rake::Task["db:test:prepare"].invoke
# Restarting the memcached server for the test
sh 'kill -9 `ps auxw | grep memcached | grep -v grep | ruby -a -e "puts gets.match(/^\\w+\\s+(\\d+)\\s+.+(memcached -d).*$/)[1]"`'
sleep(4)
sh 'memcached -d'
Rake::Task["spec"].invoke
end
This will run the migrate task on your development database before every build, setup a clean test database and find, kill and restart your memcached instance before it invokes our own spec tasks to run our BDD style testing.
Hope this will help some folks out there.
Dirk






Wouldn't it be enough to just flush memcache completely?