At work, we recently got all of our spec passing and determined that we needed to stay on top of keeping the test suite updated so that we knew that the quality of our product wasn’t compromised. To solve this, we implemented continuous integration with CruiseControl.rb.
The idea is to provide regular checks on the quality of your code. In our case, this means running the RSpec tests we’ve written for our Ruby on Rails application. Each time we commit to our git repository, CruiseControl connects to the repository and pulls down the latest code. It then runs all of our tests to let us know if anything has been broken in the latest commits. It provides a visible check to the entire team letting us know if someone committed broken code.
CruiseControl is just one of many continuous integration systems available. You can download it here and unpack it wherever its convenient. Once you have it installed, go to the root folder for CruiseControl and add your application.
cd /path/to/cruisecontrol ./cruise add your_project --source-control git --repository firstname.lastname@example.org:/your_user/your_project
I did have a few issues getting it going. The main thing I did was add the cruise_control.rb file to my project:
# Project-specific configuration for CruiseControl.rb Project.configure do |project| # Send email notifications about broken and fixed builds to email@example.com, firstname.lastname@example.org (default: send to nobody) project.email_notifier.emails = ['email@example.com'] # Set email 'from' field to firstname.lastname@example.org: # project.email_notifier.from = 'email@example.com' # Build the project by invoking rake task 'custom' # project.rake_task = 'custom' # Specify the branch you're testing # This needs to be set if you used the -b option to cruse add # project.source_control.branch = 'release' # Build the project by invoking shell script "build_my_app.sh". Keep in mind that when the script is invoked, # current working directory is [cruise data]/projects/your_project/work, so if you do not keep build_my_app.sh # in version control, it should be '../build_my_app.sh' instead project.build_command = './build_script.sh' # Ping Subversion for new revisions every 5 minutes (default: 30 seconds) # project.scheduler.polling_interval = 5.minutes # project.rake_task = 'spec' project.scheduler.polling_interval = 1.hours end
I never could get the emails to send. I was trying to send them through Gmail.
The real trick in this instance was to get all of the tests to run. I finally moved everything into a shell script so that CruiseControl would run my migrations, install my gems, and then run my tests. Here’s the script, it’s pretty simple.
#!/bin/bash rake gems:install rake db:migrate rake db:test:clone rake spec rake metrics:all
Now I keep the page up and get notified is someone broke the build.