Top Level Namespace

Defined Under Namespace

Modules: Minitest, Siyousho

Instance Method Summary collapse

Instance Method Details

#modify_proc(proc) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/siyousho.rb', line 48

def modify_proc(proc)
  buffer = Parser::Source::Buffer.new('(string)')
  buffer.source = proc.source
  parser = Parser::CurrentRuby.new
  ast = parser.parse(buffer)

  rewriter = Parser::Source::TreeRewriter.new(buffer)
  ast.children.last.children.each do |child|
    rewriter.insert_before(child.location.expression, "Siyousho.generate_parts(Siyousho.current_test,'#{Unparser.unparse(child)}')\n")
  end
  modified_code = rewriter.process

  modified_modified_code = modified_code.split("\n")[1..-2].join("\n")

  Proc.new { eval(modified_modified_code) }
end