Options for a continuous integration environment with RoR?

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.

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

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

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 [email protected] 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.

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

On Jan 14, 2008 12:03 AM, Thibaut Barrère [email protected]
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.

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 - about writing software
http://evolvingworker.com - tools for a better day

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. [email protected] 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.

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

On Jan 14, 2008 12:03 AM, Thibaut Barrère [email protected]
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.

On Jan 14, 2008 3:02 PM, Ryan B. [email protected] 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:

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.

And how do we implement this into Rspec?

On Jan 15, 2008 10:33 AM, Will S. [email protected] wrote:

to go.

Will.


Ryan B.

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

On Jan 14, 2008 3:54 PM, Will S. [email protected] 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.

On Jan 14, 2008 4:23 PM, Ryan B. [email protected] 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://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. :slight_smile:

Will.

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.

On Jan 15, 2008 8:25 PM, Mark W. [email protected] wrote:

On Jan 14, 2:11pm, “Will S.” [email protected] 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.

On Jan 14, 2:11 pm, “Will S.” [email protected] 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

On Jan 16, 2:39 pm, “Will S.” [email protected] wrote:

On Jan 15, 2008 8:25 PM, Mark W. [email protected] 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