mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
8a4ef0c16c
* Split out LogWriter from Events * Improve code comment * Fix constructor interfaces * Fix file includes * Fix specs and requires * Fix LogWriter * More fixes * Fix tests * Fix specs * Fix spec * Fix more specs * Refactor: Split out LogWriter from Events * Improve comments * Fix bundle pruner Co-authored-by: shields <shields@tablecheck.com>
60 lines
959 B
Ruby
60 lines
959 B
Ruby
require 'puma/events'
|
|
require_relative "helper"
|
|
|
|
class TestEvents < Minitest::Test
|
|
def test_register_callback_with_block
|
|
res = false
|
|
|
|
events = Puma::Events.new
|
|
|
|
events.register(:exec) { res = true }
|
|
|
|
events.fire(:exec)
|
|
|
|
assert_equal true, res
|
|
end
|
|
|
|
def test_register_callback_with_object
|
|
obj = Object.new
|
|
|
|
def obj.res
|
|
@res || false
|
|
end
|
|
|
|
def obj.call
|
|
@res = true
|
|
end
|
|
|
|
events = Puma::Events.new
|
|
|
|
events.register(:exec, obj)
|
|
|
|
events.fire(:exec)
|
|
|
|
assert_equal true, obj.res
|
|
end
|
|
|
|
def test_fire_callback_with_multiple_arguments
|
|
res = []
|
|
|
|
events = Puma::Events.new
|
|
|
|
events.register(:exec) { |*args| res.concat(args) }
|
|
|
|
events.fire(:exec, :foo, :bar, :baz)
|
|
|
|
assert_equal [:foo, :bar, :baz], res
|
|
end
|
|
|
|
def test_on_booted_callback
|
|
res = false
|
|
|
|
events = Puma::Events.new
|
|
|
|
events.on_booted { res = true }
|
|
|
|
events.fire_on_booted!
|
|
|
|
assert res
|
|
end
|
|
end
|