Sha256: 5e76beca9e6b0b03dc62f99c4a2eea0dd5e1a1e82c0ccc49067f23d16ce8e346

Contents?: true

Size: 923 Bytes

Versions: 3

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

require 'pathname'
require_relative '../lib/thinreports'

class Thinreports::Example
  ROOT = Pathname.new File.expand_path('..', __FILE__)

  attr_reader :name, :description

  def initialize(name, description)
    @name = name
    @description = description
  end

  def start
    print "[#{name}] #{description}: "
  end

  def success
    print "ok#{$/}"
  end

  def error(e)
    puts "#{$/}ERROR: #{e}"
    puts e.backtrace
  end

  def layout_filename
    resource("#{@name}.tlf")
  end

  def output_filename
    resource("#{@name}.pdf")
  end

  def resource(filename = nil)
    path = ROOT.join @name.to_s
    filename ? path.join(filename).to_s : path.to_s
  end
end

def example(name, description = nil, &block)
  ex = Thinreports::Example.new(name, description)
  ex.start
  block.arity == 1 ? block.call(ex) : ex.instance_eval(&block)
  ex.success
rescue => e
  ex.error(e)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thinreports-0.10.2 examples/helper.rb
thinreports-0.10.1 examples/helper.rb
thinreports-0.10.0 examples/helper.rb