Sha256: 6d8f5f4d087d25dae9c746c42af7d7da4815fe5b132f03fc960d521b0f6fba35

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 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
      while string.length > 0
        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

class Minitest::Spec
  include TestHelper
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hexapdf-0.6.0 test/test_helper.rb