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

Delegate unhandled messages to the current session instance.



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

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.



305
306
307
# File 'lib/action_dispatch/testing/integration.rb', line 305

def app
  @app
end

Instance Method Details

#before_setupObject

:nodoc:



312
313
314
315
# File 'lib/action_dispatch/testing/integration.rb', line 312

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.



375
376
377
378
379
# File 'lib/action_dispatch/testing/integration.rb', line 375

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

#create_session(app) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
# File 'lib/action_dispatch/testing/integration.rb', line 327

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



381
382
383
# File 'lib/action_dispatch/testing/integration.rb', line 381

def default_url_options
  integration_session.default_url_options
end

#default_url_options=(options) ⇒ Object



385
386
387
# File 'lib/action_dispatch/testing/integration.rb', line 385

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

#initialize(*args, &blk) ⇒ Object



307
308
309
310
# File 'lib/action_dispatch/testing/integration.rb', line 307

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

#integration_sessionObject



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

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.



366
367
368
369
370
371
# File 'lib/action_dispatch/testing/integration.rb', line 366

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

#remove!Object

:nodoc:



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

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.



323
324
325
# File 'lib/action_dispatch/testing/integration.rb', line 323

def reset!
  @integration_session = create_session(app)
end