class PryTest::Template

Public Class Methods

new(context) click to toggle source
# File lib/pry-test/formatters/template.rb, line 15
def initialize(context)
  @context = context
end
view(name) click to toggle source
# File lib/pry-test/formatters/template.rb, line 10
def self.view(name)
  @views ||= {}
  @views[name] ||= File.read(File.expand_path("../views/#{name}.txt.erb", __FILE__))
end

Public Instance Methods

assert_lines(assert) click to toggle source
# File lib/pry-test/formatters/template.rb, line 37
def assert_lines(assert)
  index = assert[:line_num] - 1
  start = index - 2
  start = 0 if start <= 0
  finish = index + 2
  finish = assert[:lines].length - 1 if finish >= assert[:lines].length
  (start..finish).map do |i|
    {
      line_num: (i + 1),
      line: assert[:lines][i],
      color: (i == index ? :red : :gray)
    }
  end
end
duration_color(duration) click to toggle source
# File lib/pry-test/formatters/template.rb, line 32
def duration_color(duration)
  return :yellow if @context.duration <= 0.01
  :red
end
partial(name, *collection) click to toggle source
# File lib/pry-test/formatters/template.rb, line 25
def partial(name, *collection)
  return render_to_string(name) if collection.empty?
  collection.map { |item|
    Template.new(item).render_to_string(name)
  }.join("\n")
end
render_to_string(name) click to toggle source
# File lib/pry-test/formatters/template.rb, line 19
def render_to_string(name)
  instance_eval do
    ERB.new(self.class.view(name), trim_mode: "-").result(binding)
  end
end