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

Make NullIO#read mimic IO#read #90

Merged
merged 2 commits into from Apr 30, 2012
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
7 changes: 3 additions & 4 deletions lib/puma/null_io.rb
Expand Up @@ -4,7 +4,6 @@ module Puma
# Used as the value for rack.input when the request has no body.
#
class NullIO

# Always returns nil
#
def gets
Expand All @@ -16,10 +15,10 @@ def gets
def each
end

# Always returns nil
# Mimics IO#read with no data
#
def read(count)
nil
def read(count=nil,buffer=nil)
(count && count > 0) ? nil : ""
end

# Does nothing
Expand Down
31 changes: 31 additions & 0 deletions test/test_null_io.rb
@@ -0,0 +1,31 @@
require 'puma/null_io'
require 'test/unit'

class TestNullIO < Test::Unit::TestCase
attr_accessor :nio
def setup
self.nio = Puma::NullIO.new
end

def test_read_with_no_arguments
assert_equal "", nio.read
end

def test_read_with_nil_length
assert_equal "", nio.read(nil)
end

def test_read_with_zero_length
assert_equal "", nio.read(0)
end

def test_read_with_positive_integer_length
assert_nil nio.read(1)
end

def test_read_with_length_and_buffer
buf = ""
assert_nil nio.read(1,buf)
assert_equal "", buf
end
end