class PowerAssert::BlockContext

Public Class Methods

new(assertion_proc_or_source, assertion_method, source_binding) click to toggle source
Calls superclass method PowerAssert::Context::new
# File power_assert-2.0.3/lib/power_assert/context.rb, line 162
def initialize(assertion_proc_or_source, assertion_method, source_binding)
  super(0)
  if assertion_proc_or_source.respond_to?(:to_proc)
    @assertion_proc = assertion_proc_or_source.to_proc
    line = nil
  else
    @assertion_proc = source_binding.eval "Proc.new {#{assertion_proc_or_source}}"
    line = assertion_proc_or_source
  end
  @parser = Parser::DUMMY
  @trace_call = TracePoint.new(:call, :c_call) do
    if PowerAssert.app_context? and Thread.current == @target_thread
      @trace_call.disable
      locs = PowerAssert.app_caller_locations
      path = locs.last.path
      lineno = locs.last.lineno
      if File.exist?(path)
        line ||= File.open(path) {|fp| fp.each_line.drop(lineno - 1).first }
      end
      if line
        @parser = Parser.new(line, path, lineno, @assertion_proc.binding, assertion_method.to_s, @assertion_proc)
      end
    end
  end
end

Public Instance Methods

yield() click to toggle source
# File power_assert-2.0.3/lib/power_assert/context.rb, line 188
def yield
  @fired = true
  invoke_yield(&@assertion_proc)
end

Private Instance Methods

invoke_yield() { || ... } click to toggle source
# File power_assert-2.0.3/lib/power_assert/context.rb, line 195
def invoke_yield
  @trace_return.enable do
    @trace_call.enable do
      yield
    end
  end
end