| Module | ActionController::Integration::Runner |
| In: |
vendor/rails/actionpack/lib/action_controller/integration.rb
|
Delegate unhandled messages to the current session instance.
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 446
446: def method_missing(sym, *args, &block)
447: reset! unless @integration_session
448: returning @integration_session.send!(sym, *args, &block) do
449: copy_session_variables!
450: end
451: end
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.
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 413
413: def open_session
414: session = Integration::Session.new
415:
416: # delegate the fixture accessors back to the test instance
417: extras = Module.new { attr_accessor :delegate, :test_result }
418: if self.class.respond_to?(:fixture_table_names)
419: self.class.fixture_table_names.each do |table_name|
420: name = table_name.tr(".", "_")
421: next unless respond_to?(name)
422: extras.send!(:define_method, name) { |*args| delegate.send(name, *args) }
423: end
424: end
425:
426: # delegate add_assertion to the test case
427: extras.send!(:define_method, :add_assertion) { test_result.add_assertion }
428: session.extend(extras)
429: session.delegate = self
430: session.test_result = @_result
431:
432: yield session if block_given?
433: session
434: end