1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/test/test_events.rb
Johnny Shields 8a4ef0c16c
[WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798)
* 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>
2022-02-05 10:06:22 -07:00

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