class DispatcherTest

Public Instance Methods

setup() click to toggle source
# File actionpack/test/dispatch/callbacks_test.rb, line 16
def setup
  Foo.a, Foo.b = 0, 0
  ActionDispatch::Callbacks.reset_callbacks(:call)
end
test_before_and_after_callbacks() click to toggle source
# File actionpack/test/dispatch/callbacks_test.rb, line 21
def test_before_and_after_callbacks
  ActionDispatch::Callbacks.before { |*args| Foo.a += 1; Foo.b += 1 }
  ActionDispatch::Callbacks.after  { |*args| Foo.a += 1; Foo.b += 1 }

  dispatch
  assert_equal 2, Foo.a
  assert_equal 2, Foo.b

  dispatch
  assert_equal 4, Foo.a
  assert_equal 4, Foo.b

  dispatch do
    raise "error"
  end rescue nil
  assert_equal 6, Foo.a
  assert_equal 6, Foo.b
end

Private Instance Methods

dispatch(&block) click to toggle source
# File actionpack/test/dispatch/callbacks_test.rb, line 42
def dispatch(&block)
  ActionDispatch::Callbacks.new(block || DummyApp.new).call(
    "rack.input" => StringIO.new("")
  )
end