mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Add some tests to Puma::Events (#1161)
* Add some tests to Puma::Events class. * Add missing require to Puma::Events.
This commit is contained in:
parent
1109f9d881
commit
57c6dd947f
2 changed files with 59 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
require 'puma/const'
|
||||
require "puma/null_io"
|
||||
require 'stringio'
|
||||
|
||||
module Puma
|
||||
|
|
58
test/test_events.rb
Normal file
58
test/test_events.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
require "test_helper"
|
||||
|
||||
require "puma/events"
|
||||
|
||||
class TestEvents < Minitest::Test
|
||||
def test_null
|
||||
events = Puma::Events.null
|
||||
|
||||
assert_kind_of Puma::NullIO, events.stdout
|
||||
assert_kind_of Puma::NullIO, events.stderr
|
||||
end
|
||||
|
||||
def test_strings
|
||||
events = Puma::Events.strings
|
||||
|
||||
assert_kind_of StringIO, events.stdout
|
||||
assert_kind_of StringIO, events.stderr
|
||||
end
|
||||
|
||||
def test_stdio
|
||||
events = Puma::Events.stdio
|
||||
|
||||
assert_equal STDOUT, events.stdout
|
||||
assert_equal STDERR, events.stderr
|
||||
end
|
||||
|
||||
def test_register_callback_with_block
|
||||
res = false
|
||||
|
||||
events = Puma::Events.null
|
||||
|
||||
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.null
|
||||
|
||||
events.register(:exec, obj)
|
||||
|
||||
events.fire(:exec)
|
||||
|
||||
assert_equal true, obj.res
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue