Module: ActionController::Integration::Runner

Included in:
ActionController::IntegrationTest, RequestProfiler::Sandbox
Defined in:
lib/action_controller/integration.rb

Instance Method Summary collapse

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.



496
497
498
499
500
501
# File 'lib/action_controller/integration.rb', line 496

def method_missing(sym, *args, &block)
  reset! unless @integration_session
  returning @integration_session.__send__(sym, *args, &block) do
    copy_session_variables!
  end
end

Instance Method Details

#copy_session_variables!Object

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



488
489
490
491
492
493
# File 'lib/action_controller/integration.rb', line 488

def copy_session_variables! #:nodoc:
  return unless @integration_session
  %w(controller response request).each do |var|
    instance_variable_set("@#{var}", @integration_session.__send__(var))
  end
end

#open_session {|session| ... } ⇒ Object

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.

Yields:

  • (session)


463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/action_controller/integration.rb', line 463

def open_session
  session = Integration::Session.new

  # delegate the fixture accessors back to the test instance
  extras = Module.new { attr_accessor :delegate, :test_result }
  if self.class.respond_to?(:fixture_table_names)
    self.class.fixture_table_names.each do |table_name|
      name = table_name.tr(".", "_")
      next unless respond_to?(name)
      extras.__send__(:define_method, name) { |*args| delegate.send(name, *args) }
    end
  end

  # delegate add_assertion to the test case
  extras.__send__(:define_method, :add_assertion) { test_result.add_assertion }
  session.extend(extras)
  session.delegate = self
  session.test_result = @_result

  yield session if block_given?
  session
end

#reset!Object

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



437
438
439
# File 'lib/action_controller/integration.rb', line 437

def reset!
  @integration_session = open_session
end