Module: ActionDispatch::Integration::Runner

Includes:
Assertions
Included in:
ActionDispatch::IntegrationTest::Behavior
Defined in:
actionpack/lib/action_dispatch/testing/integration.rb

Constant Summary collapse

APP_SESSIONS =
{}

Constants included from Assertions::ResponseAssertions

Assertions::ResponseAssertions::RESPONSE_PREDICATES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertions

#html_document

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Methods included from Assertions::RoutingAssertions

#assert_generates, #assert_recognizes, #assert_routing, #setup, #with_routing

Methods included from Assertions::ResponseAssertions

#assert_redirected_to, #assert_response

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)

Delegate unhandled messages to the current session instance.


423
424
425
426
427
428
429
430
431
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 423

def method_missing(method, *args, &block)
  if integration_session.respond_to?(method)
    integration_session.public_send(method, *args, &block).tap do
      copy_session_variables!
    end
  else
    super
  end
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app


317
318
319
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 317

def app
  @app
end

#root_sessionObject

:nodoc:


318
319
320
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 318

def root_session
  @root_session
end

Instance Method Details

#assertionsObject

:nodoc:


393
394
395
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 393

def assertions # :nodoc:
  root_session ? root_session.assertions : super
end

#assertions=(assertions) ⇒ Object

:nodoc:


397
398
399
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 397

def assertions=(assertions) # :nodoc:
  root_session ? root_session.assertions = assertions : super
end

#before_setupObject

:nodoc:


325
326
327
328
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 325

def before_setup # :nodoc:
  @app = nil
  super
end

#copy_session_variables!Object

Copy the instance variables from the current session instance into the test instance.


403
404
405
406
407
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 403

def copy_session_variables! #:nodoc:
  @controller = @integration_session.controller
  @response   = @integration_session.response
  @request    = @integration_session.request
end

#create_session(app) ⇒ Object


340
341
342
343
344
345
346
347
348
349
350
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 340

def create_session(app)
  klass = APP_SESSIONS[app] ||= Class.new(Integration::Session) {
    # If the app is a Rails app, make url_helpers available on the session.
    # This makes app.url_for and app.foo_path available in the console.
    if app.respond_to?(:routes) && app.routes.is_a?(ActionDispatch::Routing::RouteSet)
      include app.routes.url_helpers
      include app.routes.mounted_helpers
    end
  }
  klass.new(app)
end

#default_url_optionsObject


409
410
411
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 409

def default_url_options
  integration_session.default_url_options
end

#default_url_options=(options) ⇒ Object


413
414
415
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 413

def default_url_options=(options)
  integration_session.default_url_options = options
end

#initialize(*args, &blk) ⇒ Object


320
321
322
323
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 320

def initialize(*args, &blk)
  super(*args, &blk)
  @integration_session = nil
end

#integration_sessionObject


330
331
332
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 330

def integration_session
  @integration_session ||= create_session(app)
end

#open_sessionObject

Open a new session instance. If a block is given, the new session is yielded to the block before being returned.

session = open_session do |sess|
  sess.extend(CustomAssertions)
end

By default, a single session is automatically created for you, but you can use this method to open multiple sessions that ought to be tested simultaneously.


385
386
387
388
389
390
391
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 385

def open_session
  dup.tap do |session|
    session.reset!
    session.root_session = self.root_session || self
    yield session if block_given?
  end
end

#remove!Object

:nodoc:


352
353
354
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 352

def remove! # :nodoc:
  @integration_session = nil
end

#reset!Object

Reset the current session. This is useful for testing multiple sessions in a single test case.


336
337
338
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 336

def reset!
  @integration_session = create_session(app)
end