Sha256: 3d517a695251ec0faedb85d9afef806751d5943efd2c3e9462f0f234027f5944

Contents?: true

Size: 967 Bytes

Versions: 80

Compression:

Stored size: 967 Bytes

Contents

require 'spec_helper'

describe 'IOUtils' do
  let(:io) { File.open(fixtures_dir + '/test.jpg', 'rb') }
  include FormatParser::IOUtils

  describe '#safe_read' do
    it 'raises if the requested bytes are past the EOF' do
      io.seek(268118) # Seek to the actual end of the file
      expect {
        safe_read(io, 10)
      }.to raise_error(FormatParser::IOUtils::InvalidRead)
    end

    it 'raises if we ask for more bytes than are available' do
      expect {
        safe_read(io, 1_000_000)
      }.to raise_error(FormatParser::IOUtils::InvalidRead)
    end
  end

  describe '#safe_skip' do
    it 'raises on a negative skip byte amount' do
      fake_io = double
      expect {
        safe_skip(fake_io, -5)
      }.to raise_error(FormatParser::IOUtils::InvalidRead)
    end

    it 'uses #pos available on the object' do
      fake_io = double(pos: 11)
      expect(fake_io).to receive(:seek).with(11 + 5)
      safe_skip(fake_io, 5)
    end
  end
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
format_parser-2.10.0 spec/io_utils_spec.rb
format_parser-2.9.0 spec/io_utils_spec.rb
format_parser-2.8.0 spec/io_utils_spec.rb
format_parser-2.7.2 spec/io_utils_spec.rb
format_parser-2.7.1 spec/io_utils_spec.rb
format_parser-2.7.0 spec/io_utils_spec.rb
format_parser-2.6.0 spec/io_utils_spec.rb
format_parser-2.5.0 spec/io_utils_spec.rb
format_parser-2.4.5 spec/io_utils_spec.rb
format_parser-2.4.4 spec/io_utils_spec.rb
format_parser-2.4.3 spec/io_utils_spec.rb
format_parser-2.3.0 spec/io_utils_spec.rb
format_parser-2.2.1 spec/io_utils_spec.rb
format_parser-2.2.0 spec/io_utils_spec.rb
format_parser-2.1.0 spec/io_utils_spec.rb
format_parser-2.0.0 spec/io_utils_spec.rb
format_parser-2.0.0.pre.4 spec/io_utils_spec.rb
format_parser-2.0.0.pre.3 spec/io_utils_spec.rb
format_parser-2.0.0.pre.2 spec/io_utils_spec.rb
format_parser-2.0.0.pre spec/io_utils_spec.rb