module HexaPDF::TestUtils
def assert_method_invoked(object, name, *expected_values, check_block: false)
executing the block. +expected_values+ should contain arrays of arguments, one array for each
Asserts that the method +name+ of +object+ gets invoked with the +expected_values+ when
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
def assert_operators(content, operators, only_names: false, range: 0..-1)
def assert_operators(content, operators, only_names: false, range: 0..-1) processor = OperatorRecorder.new HexaPDF::Content::Parser.new.parse(content, processor) result = processor.recorded_ops[range] result.map!(&:first) if only_names assert_equal(operators, result) end
def collector(source)
def collector(source) str = ''.b while source.alive? && (data = source.resume) str << data end str end
def feeder(string, len = string.length)
def feeder(string, len = string.length) Fiber.new do until string.empty? Fiber.yield(string.slice!(0, len).force_encoding('BINARY')) end end end