# Options for a continuous integration environment with RoR?

**URL:** <https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935>\
**Category:** Rails\
**Created:** [January 14, 2008, 12:00am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935 "2008-01-14T00:00:48Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 14, 2008, 12:00am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/1 "2008-01-14T00:00:48Z")

</div>

Hi all,

I’m in the process of setting up cruisecontrolrb with RCov as our  
continuous integration server. We use rSpec for our unit tests, and  
AFAIK all the integration tests and system tests are done offline  
(i.e. scripted but not automated).

I’ve heard that many people use Cerberus or “straight” CruiseControl  
with Ruby. Is there a consensus over which one is better, if any?  
And how do people automate their system and integration tests in  
Rails? Is there a standard way to do this?

Will.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 14, 2008, 4:27am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/2 "2008-01-14T04:27:59Z")

</div>

Hi Will,

I can’t speak to server-oriented tools like CC, but you might want to  
check out ZenTest [1] for continuous testing on your own development  
machine. It has a tool called “autotest” that will run in the  
background and re-run your tests every time you save a file.

I believe all you have to do is a: `sudo gem install ZenTest` and then  
cd to the root directory of your rails project and type “autotest”.

ted

[1] [zentest | software projects | by ryan davis](http://www.zenspider.com/ZSS/Products/ZenTest/)

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 14, 2008, 8:08am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/3 "2008-01-14T08:08:21Z")

</div>

On 14 Jan 2008, at 03:36, Ryan B. wrote:

> I recommend using cruisecontrol. It should be fairly easy to set up  
> and will run all of your tests every time you commit a file. It has  
> the added option (a plugin, perhaps?) of sending a message through  
> jabber to somebody, or a list of somebodies, or even an email.
> 
> Autotest is good for your own box, but when cruisecontrol sends out  
> insults humiliating a team member because they committed a broken  
> build, it gives them the incentive not to do it again!

We’ve been using cruisecontrol.rb for a little while now and it’s  
great. We’ve added a little tweak so that it fires on a subversion  
post-commit hook rather than polling and everytime a build is broken  
it emails us.

Fred

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 14, 2008, 4:44am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/4 "2008-01-14T04:44:58Z")

</div>

I recommend using cruisecontrol. It should be fairly easy to set up and  
will  
run all of your tests every time you commit a file. It has the added  
option  
(a plugin, perhaps?) of sending a message through jabber to somebody, or  
a  
list of somebodies, or even an email.

Autotest is good for your own box, but when cruisecontrol sends out  
insults  
humiliating a team member because they committed a broken build, it  
gives  
them the incentive not to do it again!

On Jan 14, 2008 1:57 PM, Edward [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > (i.e. scripted but not automated).
> > 
> > I’ve heard that many people use Cerberus or “straight” CruiseControl  
> > with Ruby. Is there a consensus over which one is better, if any?  
> > And how do people automate their system and integration tests in  
> > Rails? Is there a standard way to do this?
> > 
> > Will.

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 14, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/5 "2008-01-14T19:45:27Z")

</div>

On Jan 14, 2008 12:03 AM, Thibaut Barrère [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m using CruiseControl.rb as well for all my Rails apps and also for  
> pure Ruby apps (including a datawarehouse project), and I’m also using  
> Rspec like you. I’ve had small issues setting up growl notifications,  
> but that’s all !

Excellent, thanks!

Will.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 14, 2008, 9:04am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/6 "2008-01-14T09:04:41Z")

</div>

I’m using CruiseControl.rb as well for all my Rails apps and also for  
pure Ruby apps (including a datawarehouse project), and I’m also using  
Rspec like you. I’ve had small issues setting up growl notifications,  
but that’s all !

cheers

## Thibaut

[http://blog.logeek.fr](http://blog.logeek.fr) - about writing software  
[http://evolvingworker.com](http://evolvingworker.com) - tools for a better day

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 15, 2008, 12:04am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/7 "2008-01-15T00:04:58Z")

</div>

Ah yes, I’m after something for this too. The problem is that I have 600  
tests and they take 300 seconds to run. I also stumbled across  
unit\_record.  
I’m sure there’s something rspec’y out there.

On Jan 15, 2008 8:41 AM, Will S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> database in rspec for those models that extend ActiveRecord? I looked  
> at unit\_record, but that seems to be for Test::Unit only.
> 
> If there isn’t, I’m just going to label anything that extends  
> ActiveRecord::Base as an integration test.
> 
> Will.
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 14, 2008, 11:12pm UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/8 "2008-01-14T23:12:16Z")

</div>

On Jan 14, 2008 12:03 AM, Thibaut Barrère [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m using CruiseControl.rb as well for all my Rails apps and also for  
> pure Ruby apps (including a datawarehouse project), and I’m also using  
> Rspec like you. I’ve had small issues setting up growl notifications,  
> but that’s all !

I don’t suppose there’s any way to decouple unit tests from the  
database in rspec for those models that extend ActiveRecord? I looked  
at unit\_record, but that seems to be for Test::Unit only.

If there isn’t, I’m just going to label anything that extends  
ActiveRecord::Base as an integration test.

Will.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 15, 2008, 12:55am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/9 "2008-01-15T00:55:49Z")

</div>

On Jan 14, 2008 3:02 PM, Ryan B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ah yes, I’m after something for this too. The problem is that I have 600  
> tests and they take 300 seconds to run. I also stumbled across unit\_record.  
> I’m sure there’s something rspec’y out there.

Looks like the best option is here:

> **[Unit testing (Rails) ActiveRecord classes without a database](http://muness.blogspot.com/2006/12/unit-testing-rails-activerecord-classes.html)**
>
> On Christmas Jay blogged about unit testing ActiveRecord classes : class PhoneNumberTest \< Test::Unit::TestCase Column = ActiveRecord::Co...

As far as I can tell, the big problem with isolation is that  
ActiveRecord depends on the database to tell it what fields it has.  
I’m not sure that a database is much better than using a config file  
for schema information in this case…

Will.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 15, 2008, 1:24am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/10 "2008-01-15T01:24:28Z")

</div>

And how do we implement this into Rspec?

On Jan 15, 2008 10:33 AM, Will S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> to go.
> 
> Will.
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 15, 2008, 1:05am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/11 "2008-01-15T01:05:12Z")

</div>

On Jan 14, 2008 3:54 PM, Will S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ActiveRecord depends on the database to tell it what fields it has.  
> I’m not sure that a database is much better than using a config file  
> for schema information in this case…

D’oh. Haven’t been reading my own posts: schema.rb IS the config file  
containing schema information in this case. So unitrecord is the way  
to go.

Will.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 15, 2008, 3:47am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/12 "2008-01-15T03:47:05Z")

</div>

On Jan 14, 2008 4:23 PM, Ryan B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> And how do we implement this into Rspec?

Move your rspec directories to follow the “jfields” method:

spec/  
unit/  
models/  
controllers/  
functional/  
models/  
controllers/

Edit spec\_helper.rb to be the following:

ENV[“RAILS\_ENV”] = “test”  
require File.expand\_path(File.dirname( **FILE** ) +  
“/…/config/environment”)  
require ‘spec’  
require ‘spec/rails’

Create a unit/unit\_spec\_helper.rb with the following:

require File.expand\_path(File.dirname( **FILE** ) + “/…/spec\_helper”)  
require ‘unit\_record’

# Disconnect ActiveRecord from the database

# [Jay Fields' Thoughts: Rails: How we test](http://blog.jayfields.com/2007/09/rails-how-we-test.html)

# 

[http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database](http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database)  
ActiveRecord::Base.disconnect!

And then change the model specs and controller specs to use  
‘unit\_spec\_helper.rb’ instead of spec\_helper.rb.

There is one outstanding bug that I haven’t resolved: request,  
response and controller have gone away, and you are now required to  
declare @request, @response and @controller in the before(:each)  
method.

Other than that, it seems to work fine. 🙂

Will.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 15, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/13 "2008-01-15T21:19:57Z")

</div>

> There is one outstanding bug that I haven’t resolved: request,  
> response and controller have gone away, and you are now required to  
> declare @request, @response and @controller in the before(:each)  
> method.

Okay, it looks like moving the controller specs out of the normal  
directory tree means there’s no autorecognition of what’s a  
controller, model, etc. So if you’re using this scheme, you have to  
define the spec type by hand:

describe FooController, “Foo Controller”, :type =\> :controller do

end

describe FooModel, “Foo Model”, :type =\> :model do

end

And so on.

Will.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 16, 2008, 11:50pm UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/14 "2008-01-16T23:50:07Z")

</div>

On Jan 15, 2008 8:25 PM, Mark W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jan 14, 2:11pm, “Will S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I don’t suppose there’s any way to decouple unit tests from the  
> > database in rspec for those models that extend ActiveRecord?
> 
> I use mock objects and other test doubles with RSpec. A unit test  
> should test a unit, not the full pathway from ActiveRecord through the  
> RAID array.

Can you explain how you mock out the ActiveRecord::Base stuff?

Will.

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 16, 2008, 5:26am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/15 "2008-01-16T05:26:27Z")

</div>

On Jan 14, 2:11 pm, “Will S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I don’t suppose there’s any way to decouple unit tests from the  
> database in rspec for those models that extend ActiveRecord?

I use mock objects and other test doubles with RSpec. A unit test  
should test a unit, not the full pathway from ActiveRecord through the  
RAID array.

///ark

---

<div class="post-metadata">

**Author:** ![combray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@combray](https://www.ruby-forum.com/u/combray)\
**Post date:** [January 17, 2008, 1:17am UTC](https://www.ruby-forum.com/t/options-for-a-continuous-integration-environment-with-ror/125935/16 "2008-01-17T01:17:14Z")

</div>

On Jan 16, 2:39 pm, “Will S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jan 15, 2008 8:25 PM, Mark W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > I don’t suppose there’s any way to decouple unit tests from the  
> > > database in rspec for those models that extend ActiveRecord?
> 
> > I use mock objects and other test doubles with RSpec. A unit test  
> > should test a unit, not the full pathway from ActiveRecord through the  
> > RAID array.
> 
> Can you explain how you mock out the ActiveRecord::Base stuff?

Mocking is definitely more useful at the functional level, where you  
can simply set up stubs and expectations for the models, then make  
sure the controller calls them correctly, meanwhile having its own  
behavior tested.

At the unit test level, I use mocks for complicated objects that the  
object under test has to deal with. As for the object under test  
itself, it’s just as easy to mock any ActiveRecord::Base methods that  
you don’t want to go through the database. You might even mock the  
connection.

///ark
