An instance of this class represents a set of requests and responses performed sequentially by a test process. Because you can instantiate multiple sessions and run them side-by-side, you can also mimic (to some limited extent) multiple simultaneous users interacting with your system.
Typically, you will instantiate a new session using IntegrationTest#open_session, rather than instantiating Integration::Session directly.
- Test::Unit::Assertions START:includes
- ActionDispatch START:includes
- ActionDispatch::Integration START:includes
- ActionDispatch START:includes
- Rails START:includes
- Rails START:includes
DEFAULT_HOST | = | "www.example.com" |
[W] | host | |
[RW] | remote_addr | The remote_addr used in the last request. |
[RW] | accept | The Accept header to send. |
[R] | controller | A reference to the controller instance used by the last request. |
[R] | request | A reference to the request instance used by the last request. |
[R] | response | A reference to the response instance used by the last request. |
[RW] | request_count | A running counter of the number of requests processed. |
Create and initialize a new Session instance.
# File actionpack/lib/action_dispatch/testing/integration.rb, line 174 174: def initialize(app) 175: super() 176: @app = app 177: 178: # If the app is a Rails app, make url_helpers available on the session 179: # This makes app.url_for and app.foo_path available in the console 180: if app.respond_to?(:routes) 181: singleton_class.class_eval do 182: include app.routes.url_helpers if app.routes.respond_to?(:url_helpers) 183: include app.routes.mounted_helpers if app.routes.respond_to?(:mounted_helpers) 184: end 185: end 186: 187: reset! 188: end
A map of the cookies returned by the last response, and which will be sent with the next request.
The hostname used in the last request.
Specify whether or not the session should mimic a secure HTTPS request.
session.https! session.https!(false)
Return true if the session is mimicking a secure HTTPS request.
if session.https? ... end
Resets the instance. This can be used to reset the state information in an existing session instance, so it can be used from a clean-slate condition.
session.reset!
# File actionpack/lib/action_dispatch/testing/integration.rb, line 207 207: def reset! 208: @https = false 209: @controller = @request = @response = nil 210: @_mock_session = nil 211: @request_count = 0 212: @url_options = nil 213: 214: self.host = DEFAULT_HOST 215: self.remote_addr = "127.0.0.1" 216: self.accept = "text/xml,application/xml,application/xhtml+xml," + 217: "text/html;q=0.9,text/plain;q=0.8,image/png," + 218: "*/*;q=0.5" 219: 220: unless defined? @named_routes_configured 221: # the helpers are made protected by default--we make them public for 222: # easier access during testing and troubleshooting. 223: @named_routes_configured = true 224: end 225: end
# File actionpack/lib/action_dispatch/testing/integration.rb, line 190 190: def url_options 191: @url_options ||= default_url_options.dup.tap do |url_options| 192: url_options.reverse_merge!(controller.url_options) if controller 193: 194: if @app.respond_to?(:routes) && @app.routes.respond_to?(:default_url_options) 195: url_options.reverse_merge!(@app.routes.default_url_options) 196: end 197: 198: url_options.reverse_merge!(:host => host, :protocol => https? ? "https" : "http") 199: end 200: end