Skip to content

Commit

Permalink
Skip ObjectSpace spec on JRuby, but add another spec for both
Browse files Browse the repository at this point in the history
  • Loading branch information
haslo committed Nov 23, 2018
1 parent 2c87a2e commit 767bc2b
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions spec/prawn/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,31 @@
end

it 'closes opened files again after getting Pathname objects' do
gc_was_disabled = GC.disable
open_files_before = ObjectSpace.each_object(File).count { |f| !f.closed? }
_info = pdf.image(Pathname.new(filename))
open_files_after = ObjectSpace.each_object(File).count { |f| !f.closed? }
GC.enable unless gc_was_disabled
if RUBY_PLATFORM == 'java'
# JRuby doesn't support ObjectSpace
expect(RUBY_PLATFORM).to eq('java')
else
gc_was_disabled = GC.disable
open_files_before = ObjectSpace.each_object(File).count { |f| !f.closed? }
_info = pdf.image(Pathname.new(filename))
open_files_after = ObjectSpace.each_object(File).count { |f| !f.closed? }
GC.enable unless gc_was_disabled

expect(open_files_after).to eq(open_files_before)
end
end

expect(open_files_after).to eq(open_files_before)
context 'with File message spy' do
before do
file_path = Pathname.new(filename)
file_content = File.new(filename, 'rb').read
allow(File).to receive(:binread).with(file_path).and_return(file_content)
end

it 'uses binread, which closes files opened from pathnames' do
_info = pdf.image(Pathname.new(filename))
expect(File).to have_received(:binread)
end
end

context 'setting the length of the bytestream' do
Expand Down

0 comments on commit 767bc2b

Please sign in to comment.