Sha256: 01f2549c56259f2d818aafedefddef6f467bd3a31b7c039fd49104a513f582e0

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

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

1 entries across 1 versions & 1 rubygems

Version Path
bindata-1.2.0 spec/spec_common.rb