Module: ActionController::Integration::Runner
- Included in:
- ActionController::IntegrationTest
- Defined in:
- lib/action_controller/integration.rb
Instance Method Summary collapse
-
#copy_session_variables! ⇒ Object
Copy the instance variables from the current session instance into the test instance.
- #initialize(*args) ⇒ Object
-
#method_missing(sym, *args, &block) ⇒ Object
Delegate unhandled messages to the current session instance.
-
#open_session(application = nil) {|session| ... } ⇒ Object
Open a new session instance.
-
#reset! ⇒ Object
Reset the current session.
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.
567 568 569 570 571 572 573 574 575 576 |
# File 'lib/action_controller/integration.rb', line 567 def method_missing(sym, *args, &block) reset! unless @integration_session if @integration_session.respond_to?(sym) @integration_session.__send__(sym, *args, &block).tap do copy_session_variables! end else super end end |
Instance Method Details
#copy_session_variables! ⇒ Object
Copy the instance variables from the current session instance into the test instance.
559 560 561 562 563 564 |
# File 'lib/action_controller/integration.rb', line 559 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 |
#initialize(*args) ⇒ Object
497 498 499 500 |
# File 'lib/action_controller/integration.rb', line 497 def initialize(*args) super @integration_session = nil end |
#open_session(application = nil) {|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.
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/action_controller/integration.rb', line 530 def open_session(application = nil) session = Integration::Session.new(application) # 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.
504 505 506 |
# File 'lib/action_controller/integration.rb', line 504 def reset! @integration_session = open_session end |