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
Context - Inherited
Instance Attribute Summary
Instance Method Summary
- #yield
- #invoke_yield private
Context - Inherited
Constructor Details
.new(assertion_proc_or_source, assertion_method, source_binding) ⇒ BlockContext
# File 'lib/power_assert/context.rb', line 149
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 ||= open(path).each_line.drop(lineno - 1).first @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 180
def invoke_yield @trace_return.enable do @trace_call.enable do yield end end end
#yield
[ GitHub ]# File 'lib/power_assert/context.rb', line 173
def yield @fired = true invoke_yield(&@assertion_proc) end