class IntegrationTest
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
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.
At its simplest, you simply extend IntegrationTest and write your tests using the get/post methods:
require "#{File.dirname(__FILE__)}/test_helper" class ExampleTest < ActionController::IntegrationTest fixtures :people def test_login # get the login page get "/login" assert_equal 200, status # post the login and follow through to the home page post "/login", :username => people(:jamis).username, :password => people(:jamis).password follow_redirect! assert_equal 200, status assert_equal "/home", path end end
However, you can also have multiple session instances open per test, and even extend those instances with assertions and methods to create a very powerful testing DSL that is specific for your application. You can even reference any named routes you happen to have defined!
require "#{File.dirname(__FILE__)}/test_helper"
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
private
module CustomAssertions
def enter(room)
# reference a named route, for maximum internal consistency!
get(room_url(:id => room.id))
assert(...)
...
end
def speak(room, message)
xml_http_request "/say/#{room.id}", :message => message
assert(...)
...
end
end
def login(who)
open_session do |sess|
sess.extend(CustomAssertions)
who = people(who)
sess.post "/login", :username => who.username,
:password => who.password
assert(...)
end
end
end
Inherits from
Includes
Used by
Subclasses (1)
Methods (inherited)
From ActionController::Integration::Runner (4)
- # method_missing
- # open_session
- # reset!
- self. new
From ActiveRecord::TestFixtures (4)
- # run_in_transaction?
- # setup_fixtures
- # teardown_fixtures
- self. included
From ActiveSupport::Testing::Assertions (4)
From ActiveSupport::Testing::Declarative (1)
- # test
From ActiveSupport::Testing::SetupAndTeardown (1)
- self. included
From ActionMailer::TestHelper (2)
From ActiveSupport::Callbacks (2)
- # run_callbacks
- self. included
From Object (37)
- # acts_like?
- # app
- # as_json
- # blank?
- # class_eval
- # create
- # create_fixtures
- # destroy
- # duplicable?
- # edit
- # find_cmd
- # helper
- # html_safe?
- # index
- # instance_exec
- # instance_variable_defined?
- # instance_variable_names
- # message
- # metaclass
- # new_session
- # presence
- # present?
- # reload!
- # returning
- # singleton_class
- # tap
- # to_json
- # to_param
- # to_query
- # try
- # unescape
- # update
- # with_options
- self. blank_slate_method_added
- self. find_hidden_method
- self. lookup_missing_generator
- self. method_added