Wednesday, March 1, 2006

New for Rails 1.1: Integration Tests

Posted by rick

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.speak(room, "anybody home?")

    david.speak(room, "hello!")

Integration Tests will be included with Rails 1.1. Get ready!