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, #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(sym, *args, &block) ⇒ Object

Delegate unhandled messages to the current session instance.



485
486
487
488
489
490
491
492
493
# File 'lib/action_dispatch/testing/integration.rb', line 485

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

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



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

def app
  @app
end

Instance Method Details

#before_setupObject

:nodoc:



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

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.



466
467
468
469
470
# File 'lib/action_dispatch/testing/integration.rb', line 466

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

#create_session(app) ⇒ Object



418
419
420
421
422
423
424
425
426
427
428
# File 'lib/action_dispatch/testing/integration.rb', line 418

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)
      include app.routes.url_helpers
      include app.routes.mounted_helpers
    end
  }
  klass.new(app)
end

#default_url_optionsObject



472
473
474
# File 'lib/action_dispatch/testing/integration.rb', line 472

def default_url_options
  integration_session.default_url_options
end

#default_url_options=(options) ⇒ Object



476
477
478
# File 'lib/action_dispatch/testing/integration.rb', line 476

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

#initialize(*args, &blk) ⇒ Object



398
399
400
401
# File 'lib/action_dispatch/testing/integration.rb', line 398

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

#integration_sessionObject



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

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.



458
459
460
461
462
# File 'lib/action_dispatch/testing/integration.rb', line 458

def open_session
  dup.tap do |session|
    yield session if block_given?
  end
end

#remove!Object

:nodoc:



430
431
432
# File 'lib/action_dispatch/testing/integration.rb', line 430

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.



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

def reset!
  @integration_session = create_session(app)
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


480
481
482
# File 'lib/action_dispatch/testing/integration.rb', line 480

def respond_to?(method, include_private = false)
  integration_session.respond_to?(method, include_private) || super
end