Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some tests to Puma::Events #1161

Merged
merged 2 commits into from Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/puma/events.rb
@@ -1,4 +1,5 @@
require 'puma/const'
require "puma/null_io"
require 'stringio'

module Puma
Expand Down
58 changes: 58 additions & 0 deletions test/test_events.rb
@@ -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