Sha256: b1152be4e7ee323a876de70ad610f0591ac0d8f1b8a9aafdfcf19407681313c9

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))

require 'spec'
require 'spec/autorun'
require 'stringio'

class Object
  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
end

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

def exception_line(ex)
  idx = ex.backtrace.find_index { |bt| /:in `should'$/ =~ bt }

  if idx
    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
  else
    raise "Required calling pattern is lambda { xxx }.should raise_error_on_line(...)"
  end
end

def raise_error_on_line(exception, line, &block)
  raise_exception(exception) do |err|
    exception_line(err).should == line
    block.call(err) if block_given?
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bindata-1.4.3 spec/spec_common.rb
bindata-1.4.2 spec/spec_common.rb
bindata-1.4.1 spec/spec_common.rb
bindata-1.4.0 spec/spec_common.rb
bindata-1.3.1 spec/spec_common.rb