123456789_123456789_123456789_123456789_123456789_

Class: PowerAssert::BlockContext

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Context
Instance Chain:
self, Context
Inherits: PowerAssert::Context
Defined in: lib/power_assert/context.rb

Class Method Summary

Instance Attribute Summary

Context - Inherited

Instance Method Summary

Constructor Details

.new(assertion_proc_or_source, assertion_method, source_binding) ⇒ BlockContext

[ GitHub ]

  
# File 'lib/power_assert/context.rb', line 164

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 |tp|
    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

Instance Method Details

#invoke_yield (private)

[ GitHub ]

  
# File 'lib/power_assert/context.rb', line 197

def invoke_yield
  @trace_return.enable do
    @trace_call.enable do
      yield
    end
  end
end

#yield

[ GitHub ]

  
# File 'lib/power_assert/context.rb', line 190

def yield
  @fired = true
  invoke_yield(&@assertion_proc)
end