Sha256: 6e465c1c6619a6ec223b8616427c4f5806c0eb93650996f4b4c1a855f99a4e65

Contents?: true

Size: 1.44 KB

Versions: 32

Compression:

Stored size: 1.44 KB

Contents

# -*- encoding: utf-8 -*-

begin
  require 'simplecov'
  SimpleCov.start do
    add_filter '/test/'
  end
rescue LoadError
end

gem 'minitest'
require 'minitest/autorun'
require 'fiber'
require 'zlib'

TEST_DATA_DIR = File.join(__dir__, 'data')
MINIMAL_PDF = File.read(File.join(TEST_DATA_DIR, 'minimal.pdf')).freeze

Minitest::Test.make_my_diffs_pretty!

module TestHelper

  # Asserts that the method +name+ of +object+ gets invoked with the +expected_values+ when
  # executing the block. +expected_values+ should contain arrays of arguments, one array for each
  # invocation of the method.
  def assert_method_invoked(object, name, *expected_values, check_block: false)
    args = []
    block = []
    object.define_singleton_method(name) {|*la, &lb| args << la; block << lb }
    yield
    assert_equal(expected_values, args, "Incorrect arguments for #{object.class}##{name}")
    block.each do |block_arg|
      assert_kind_of(Proc, block_arg, "Missing block for #{object.class}##{name}") if check_block
    end
  ensure
    object.singleton_class.send(:remove_method, name)
  end

  module_function

  def feeder(string, len = string.length)
    Fiber.new do
      until string.empty?
        Fiber.yield(string.slice!(0, len).force_encoding('BINARY'))
      end
    end
  end

  def collector(source)
    str = ''.force_encoding('BINARY')
    while source.alive? && (data = source.resume)
      str << data
    end
    str
  end
end

Minitest::Spec.include(TestHelper)

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
hexapdf-0.23.0 test/test_helper.rb
hexapdf-0.22.0 test/test_helper.rb
hexapdf-0.21.1 test/test_helper.rb
hexapdf-0.21.0 test/test_helper.rb
hexapdf-0.20.4 test/test_helper.rb
hexapdf-0.20.3 test/test_helper.rb
hexapdf-0.20.2 test/test_helper.rb
hexapdf-0.20.1 test/test_helper.rb
hexapdf-0.20.0 test/test_helper.rb
hexapdf-0.19.3 test/test_helper.rb
hexapdf-0.19.2 test/test_helper.rb
hexapdf-0.19.1 test/test_helper.rb
hexapdf-0.19.0 test/test_helper.rb
hexapdf-0.18.0 test/test_helper.rb
hexapdf-0.17.3 test/test_helper.rb
hexapdf-0.17.2 test/test_helper.rb
hexapdf-0.16.0 test/test_helper.rb
hexapdf-0.15.9 test/test_helper.rb
hexapdf-0.15.8 test/test_helper.rb
hexapdf-0.15.7 test/test_helper.rb