Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Don't peek unless the object quacks like an IO #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/dimensions/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def peek
end

def no_peeking?
@reader.width || closed? || pos != 0
@reader.width || (!respond_to?(:closed?) || closed?) || (!respond_to?(:pos) || pos != 0)
end
end
end
6 changes: 6 additions & 0 deletions test/test_io.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'dimensions/test_case'

class TestIO < Dimensions::TestCase
class NotIO; end

def test_extends_io
with_extended_file do |file|
assert file.is_a?(Dimensions::IO)
Expand Down Expand Up @@ -31,6 +33,10 @@ def test_skips_peeking_if_offset
end
end

def test_skips_peeking_unless_quacks_right
assert_equal nil, Dimensions(NotIO.new).dimensions
end

private
def with_extended_file
with_fixture("screenshot.png") do |file|
Expand Down