Customizing CruiseControl build for RSpec

Published on Author Akhil Bansal2 Comments

Yesterday I posted about CruiseControl for Rails projects. It was working fine with all my rails projects using traditional test cases, But today I faced a problem with a project using RSpec. Actually, By default CruiseControl follows the following step to build:

  1. rake db:test:purge
  2. rake db:migrate
  3. rake test

This default was not working with my last project As I was using RSpec for my project. I found that we can overwrite default way of building by creating a rake task named cruise in our project. Means by building CruiseControl will run your custom rake task only, so you have to take care of all other things i.e. migrate etc.

Hence I created following rake task in RAILS_ROOT/lib/tasks/custom_cc.rake

desc 'Custom curise task for RSpec'
task :cruise do
      ENV['RAILS_ENV'] = 'test'

      if File.exists?(Dir.pwd + "/config/database.yml")
        if Dir[Dir.pwd + "/db/migrate/*.rb"].empty?
          raise "No migration scripts found in db/migrate/ but database.yml exists, " +
                "CruiseControl won't be able to build the latest test database. Build aborted."
        end

        # perform standard Rails database cleanup/preparation tasks if they are defined in project
        # this is necessary because there is no up-to-date development database on a continuous integration box
        if Rake.application.lookup('db:test:purge')
          CruiseControl::invoke_rake_task 'db:test:purge'
        end

        if Rake.application.lookup('db:migrate')
          CruiseControl::reconnect
          CruiseControl::invoke_rake_task 'db:migrate'
        end
      end

      CruiseControl::invoke_rake_task 'spec:all'
end

and it worked for my rails project using RSpec.

2 Responses to Customizing CruiseControl build for RSpec

Leave a Reply

Your email address will not be published. Required fields are marked *