Module: ActionDispatch::Integration::Runner

Includes:
Assertions
Included in:
ActionDispatch::IntegrationTest::Behavior
Defined in:
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 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) ⇒ Object (private)

Delegate unhandled messages to the current session instance.



432
433
434
435
436
437
438
439
440
# File 'lib/action_dispatch/testing/integration.rb', line 432

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

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



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

def app
  @app
end

#root_sessionObject

:nodoc:



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

def root_session
  @root_session
end

Instance Method Details

#assertionsObject

:nodoc:



402
403
404
# File 'lib/action_dispatch/testing/integration.rb', line 402

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

#assertions=(assertions) ⇒ Object

:nodoc:



406
407
408
# File 'lib/action_dispatch/testing/integration.rb', line 406

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

#before_setupObject

:nodoc:



337
338
339
340
# File 'lib/action_dispatch/testing/integration.rb', line 337

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.



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

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

#create_session(app) ⇒ Object



352
353
354
355
356
357
358
359
360
361
362
# File 'lib/action_dispatch/testing/integration.rb', line 352

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



418
419
420
# File 'lib/action_dispatch/testing/integration.rb', line 418

def default_url_options
  integration_session.default_url_options
end

#default_url_options=(options) ⇒ Object



422
423
424
# File 'lib/action_dispatch/testing/integration.rb', line 422

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

#initialize(*args, &blk) ⇒ Object



332
333
334
335
# File 'lib/action_dispatch/testing/integration.rb', line 332

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

#integration_sessionObject



342
343
344
# File 'lib/action_dispatch/testing/integration.rb', line 342

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.



394
395
396
397
398
399
400
# File 'lib/action_dispatch/testing/integration.rb', line 394

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:



364
365
366
# File 'lib/action_dispatch/testing/integration.rb', line 364

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.



348
349
350
# File 'lib/action_dispatch/testing/integration.rb', line 348

def reset!
  @integration_session = create_session(app)
end