New for Rails 1.1: Integration Tests
Posted by rick March 01, 2006 @ 04:43 AM
If you’ve ever tried to properly test complex scenarios involving multiple controller actions, you will notice that the Rails Functional Tests fall flat. The new Integration Tests, which have just been introduced into the Rails trunk, will solve that. From the documentation:
An IntegrationTest is one that spans multiple controllers and actions, tying them all together to ensure they work together as expected. It tests more completely than either unit or functional tests do, exercising the entire stack, from the dispatcher to the database.
The provided example also shows a glimpse into the testing DSL that is used in Campfire:
class AdvancedTest < ActionController::IntegrationTest
fixtures :people, :rooms
def test_login_and_speak
jamis, david = login(:jamis), login(:david)
room = rooms(:office)
jamis.enter(room)
jamis.speak(room, "anybody home?")
david.enter(room)
david.speak(room, "hello!")
end
end
Integration Tests will be included with Rails 1.1. Get ready!

Great stuff. However, the code sample included in this weblog entry slightly confused me. jamis.enter() etc looked like you were simply calling model methods, so I started to wonder how this is any different from standard unit testing. I then noticed the sample code (in the actual code you linked) includes additional custom assertions that actually make clear what you’re doing here.
That’s true. I just didn’t want to include too much code in the post. That snippet highlights the great part of integration testing: the custom dsl you write for your app.
testing is something i really want to get into—i’m from a c++ etc background so it’s not really in my (old) paradigm. feel like i’m getting left behind here.
Can anyone recommend any decent resources, either in online or physical form ? i suffer from the ‘where do i start’ problem.
jak
What does DSL stand for?
“Domain-specific language”: Basically, a little mini-language built on top of Ruby for solving some particular problem.
jakdak, I’m particularly fond of Kent Beck’s book, “Test Driven Development”. He walks through a whole bunch of sample programs, and really shows how testing can help shape better code.
A good idea in principle, but these simply aren’t integration tests, not in the true sense. These are functional/acceptance tests (and what Rails already calls functional tests are just unit tests).
I’ve posted about this on the Rails mailing list, but heres another link:
http://www.sitepoint.com/forums/showthread.php?t=354597
It would be nice if the Rails developers could sort out their testing semantics – I know Rails is opinionated software but in my view this is one opinion that is based on a misunderstanding of testing semantics. It would be nice if Rails could get this right for 1.1
Anyone know when Rails 1.1 is expected for release?
The original announcement mentioned February 2006 but that month has passed and there’s no mention of a new release date.
Providing an update would help some of us plan better…
Anyone know when Rails 1.1 is expected for release?
The original announcement mentioned February 2006 but that month has passed and there’s no mention of a new release date.
Providing an update would help some of us plan better…
Anyone know when Rails 1.1 is expected for release?
The original announcement mentioned February 2006 but that month has passed and there’s no mention of a new release date.
Providing an update would help some of us plan better…