Sha256: 3ef5957c4a5743ea99a14ca1840b6185d7610fc07f747d77c5b5123d3ead2bd4

Contents?: true

Size: 1.41 KB

Versions: 16

Compression:

Stored size: 1.41 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

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.send(:include, TestHelper)

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hexapdf-0.11.9 test/test_helper.rb
hexapdf-0.11.8 test/test_helper.rb
hexapdf-0.11.7 test/test_helper.rb
hexapdf-0.11.6 test/test_helper.rb
hexapdf-0.11.5 test/test_helper.rb
hexapdf-0.11.4 test/test_helper.rb
hexapdf-0.11.3 test/test_helper.rb
hexapdf-0.11.2 test/test_helper.rb
hexapdf-0.11.1 test/test_helper.rb
hexapdf-0.11.0 test/test_helper.rb
hexapdf-0.10.0 test/test_helper.rb
hexapdf-0.9.3 test/test_helper.rb
hexapdf-0.9.2 test/test_helper.rb
hexapdf-0.9.1 test/test_helper.rb
hexapdf-0.9.0 test/test_helper.rb
hexapdf-0.8.0 test/test_helper.rb