Class: ActionDispatch::IntegrationTest
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::ActiveSupport::TestCase,
::ActiveSupport::DescendantsTracker,
::ActiveSupport::Testing::Declarative,
Minitest::Test
|
|
Instance Chain:
self,
Routing::UrlFor,
Routing::PolymorphicRoutes,
::ActionController::ModelNaming,
::ActionController::TemplateAssertions,
Integration::Runner,
Assertions,
Rails::Dom::Testing::Assertions,
Assertions::RoutingAssertions,
Assertions::ResponseAssertions,
::ActiveSupport::TestCase,
::ActiveRecord::TestFixtures,
::ActiveSupport::Testing::TimeHelpers,
::ActiveSupport::Testing::Assertions,
::ActiveSupport::Callbacks,
::ActiveSupport::Testing::SetupAndTeardown,
Minitest::Test
|
|
Inherits: |
ActiveSupport::TestCase
|
Defined in: | actionpack/lib/action_dispatch/testing/integration.rb, railties/lib/rails/test_help.rb |
Overview
An integration test 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 "test_helper"
class ExampleTest < ActionDispatch::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 "test_helper"
class AdvancedTest < ActionDispatch::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
Constant Summary
::ActiveSupport::Callbacks - Inherited
::ActiveSupport::TestCase - Inherited
::ActionController::TemplateAssertions - Included
Routing::UrlFor - Attributes & Methods
Class Attribute Summary
- .app rw
- .app=(app) rw
::ActiveSupport::TestCase - Inherited
.config, .config?, .fixture_class_names, .fixture_class_names?, .fixture_path, .fixture_path?, .fixture_table_names, .fixture_table_names?, .pre_loaded_fixtures, .pre_loaded_fixtures?, | |
.test_order | Returns the order in which test cases are run. |
.test_order= | Sets the order in which test cases are run. |
.use_instantiated_fixtures, .use_instantiated_fixtures?, .use_transactional_fixtures, .use_transactional_fixtures? |
Class Method Summary
::ActiveSupport::TestCase - Inherited
::ActiveSupport::DescendantsTracker - Inherited
clear, descendants, direct_descendants, | |
store_inherited | This is the only method that is not thread safe, but is only ever called during the eager loading phase. |
::ActiveSupport::Testing::Declarative - Extended
Instance Attribute Summary
Integration::Runner - Included
::ActiveSupport::TestCase - Inherited
::ActiveRecord::TestFixtures - Included
Instance Method Summary
Routing::UrlFor - Included
#initialize, | |
#url_for | Generate a url based on the options provided, default_url_options and the routes defined in routes.rb. |
#url_options | Hook overridden in controller to add request information with .default_url_options. |
Routing::PolymorphicRoutes - Included
#polymorphic_path | Returns the path component of a URL for the given record. |
#polymorphic_url | Constructs a call to a named RESTful route for the given record and returns the resulting URL string. |
::ActionController::ModelNaming - Included
#convert_to_model | Converts the given object to an ::ActiveModel compliant one. |
#model_name_from_record_or_class |
::ActionController::TemplateAssertions - Included
#assert_template | Asserts that the request was rendered with the appropriate template file or partials. |
#process, #reset_template_assertion, #setup_subscriptions, #teardown_subscriptions |
Integration::Runner - Included
#app, | |
#method_missing | Delegate unhandled messages to the current session instance. |
#open_session | Open a new session instance. |
#reset! | Reset the current session. |
#respond_to? |
Assertions - Included
Assertions::RoutingAssertions - Included
#assert_generates | Asserts that the provided options can be used to generate the provided path. |
#assert_recognizes | Asserts that the routing of the given |
#assert_routing | Asserts that path and options match both ways; in other words, it verifies that |
#method_missing | ROUTES TODO: These assertions should really work in an integration context. |
#with_routing | A helper to make it easier to test different route configurations. |
Assertions::ResponseAssertions - Included
#assert_redirected_to | Assert that the redirection options passed in match those of the redirect called in the latest action. |
#assert_response | Asserts that the response is one of the following types: |
::ActiveSupport::TestCase - Inherited
#assert_no_match, #assert_not_empty, #assert_not_equal, #assert_not_in_delta, #assert_not_in_epsilon, #assert_not_includes, #assert_not_instance_of, #assert_not_kind_of, #assert_not_nil, #assert_not_operator, #assert_not_predicate, #assert_not_respond_to, #assert_not_same, | |
#assert_nothing_raised | Fails if the block raises an exception. |
#assert_raise | test/unit backwards compatibility methods. |
#method_name |
::ActiveRecord::TestFixtures - Included
::ActiveSupport::Testing::TimeHelpers - Included
#travel | Changes current time to the time in the future or in the past by a given time difference by stubbing |
#travel_back | Returns the current time back to its original state, by removing the stubs added by |
#travel_to | Changes current time to the given time by stubbing |
::ActiveSupport::Testing::Assertions - Included
#assert_difference | Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. |
#assert_no_difference | Assertion that the numeric result of evaluating an expression is not changed before and after invoking the passed in block. |
#assert_not | Assert that an expression is not truthy. |
::ActiveSupport::Callbacks - Inherited
#run_callbacks | Runs the callbacks for the given event. |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActionDispatch::Integration::Runner
Class Attribute Details
.app (rw)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 493
def self.app @@app || ActionDispatch.test_app end
.app=(app) (rw)
[ GitHub ].default_url_options (rw)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 91
class_attribute :
.default_url_options? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 91
class_attribute :
Instance Attribute Details
#default_url_options (rw)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 91
class_attribute :
#default_url_options? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 91
class_attribute :
Instance Method Details
#app
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 501
def app super || self.class.app end
#document_root_element
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 510
def document_root_element html_document.root end
#url_options
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 505
def reset! unless integration_session integration_session. end