Sha256: 55382888973eaa8ce462c8cf63d6cb36223a5136afea9155ba7bd70a75468720

Contents?: true

Size: 1.44 KB

Versions: 20

Compression:

Stored size: 1.44 KB

Contents

require 'rubygems'

require 'coveralls'
Coveralls.wear!

require 'minitest/autorun'
require 'stringio'

$LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
require 'bindata'

class StringIO
  # Returns the value that was written to the io
  def value
    rewind
    read
  end
end

module Kernel
  def expose_methods_for_testing
    cls = (Class === self) ? self : (class << self ; self; end)
    private_method_names = cls.private_instance_methods - Object.private_instance_methods
    cls.send(:public, *private_method_names)

    protected_method_names = cls.protected_instance_methods - Object.protected_instance_methods
    cls.send(:public, *protected_method_names)
  end

  def value_read_from_written
    self.class.read(self.to_binary_s)
  end

  def must_equal_binary(expected)
    must_equal expected.dup.force_encoding(Encoding::BINARY)
  end

  def must_raise_on_line(exp, line, msg = nil)
    ex = self.must_raise exp
    ex.message.must_equal msg if msg

    idx = ex.backtrace.find_index { |bt| /:in `must_raise_on_line'$/ =~ bt }

    line_num_regex = /.*:(\d+)(:.*|$)/
    err_line = line_num_regex.match(ex.backtrace[0])[1].to_i
    ref_line = line_num_regex.match(ex.backtrace[idx + 1])[1].to_i

    (err_line - ref_line).must_equal line
  end

  def must_warn(msg, &block)
    result = ""
    callable = proc { |str|
      result = str
    }
    self.stub(:warn, callable) do
      block.call
    end
    result.must_equal msg
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
bindata-2.4.13 test/test_helper.rb
bindata-2.4.12 test/test_helper.rb
bindata-2.4.11 test/test_helper.rb
bindata-2.4.10 test/test_helper.rb
bindata-2.4.9 test/test_helper.rb
bindata-2.4.8 test/test_helper.rb
bindata-2.4.7 test/test_helper.rb
bindata-2.4.6 test/test_helper.rb
bindata-2.4.5 test/test_helper.rb
bindata-2.4.4 test/test_helper.rb
bindata-2.4.3 test/test_helper.rb
bindata-2.4.2 test/test_helper.rb
bindata-2.4.1 test/test_helper.rb
bindata-2.4.0 test/test_helper.rb
bindata-2.3.5 test/test_helper.rb
bindata-2.3.4 test/test_helper.rb
bindata-2.3.3 test/test_helper.rb
bindata-2.3.2 test/test_helper.rb
bindata-2.3.1 test/test_helper.rb
bindata-2.3.0 test/test_helper.rb