Sha256: 2f44ed85aaceb869bc41848b9b01ba97a3a8f83e4ad3a154827e557cef8c4f0f

Contents?: true

Size: 1.71 KB

Versions: 5

Compression:

Stored size: 1.71 KB

Contents

require 'pad_utils'
require 'PADGEM_GEM_RUBY_NAME'

class Test

  attr_accessor :test_name, :errors, :notes, :result

  def initialize(test_name)
    @test_name = test_name
    @errors = []
    @notes = []
    @result = {name: test_name, errors: @errors.length}
  end

  def explain
    puts
    PadUtils.puts_c "Running: #{@test_name}...", :green
    puts
  end

  def raise_error(e)
    puts
    PadUtils.puts_c "Error in #{@test_name}: ", :error
    puts "#{e.message} (#{e.class.name})"
    stack = e.backtrace.inspect.split(",")
    stack.each do |s|
      puts "\t#{s}"
    end
    puts
  end

  def leave
    puts
    PadUtils.puts_c "Finished running: #{@test_name}", @errors.length < 1 ? :green : :error

    if @errors.length < 1
      PadUtils.puts_c "- 0 errors", :green
    else
      PadUtils.puts_c "- #{@errors.length} error(s):", :error
      @errors.each do |error|
        PadUtils.puts_c "--> #{error}"
      end
    end
    puts

    if @notes.length > 0
      PadUtils.puts_c "- #{@notes.length} note(s):", :green
      @notes.each do |note|
        PadUtils.puts_c "--> #{note}"
      end
      puts
    end

    PadUtils.puts_c "--------------------", :green
    puts
  end

  def run
    explain
    prepare
    runner
    cleanup
    leave
    @result[:errors] = @errors.length
    @result
  end

  def runner
    run_test
  rescue Exception => e
    @errors << "Error message: #{e.message}"
    raise_error(e)
  end

  def run_test
    PadUtils.puts_c "'#{@test_name} run_test method' not implemented!", :error
  end

  def prepare
    PadUtils.puts_c "'#{@test_name} prepare method' not implemented!", :error
  end

  def cleanup
    PadUtils.puts_c "'#{@test_name} cleanup method' not implemented!", :error
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pad_gem-1.4.0 lib/foundation/test/template/test.rb
pad_gem-1.3.0 lib/foundation/test/template/test.rb
pad_gem-1.2.0 lib/foundation/test/template/test.rb
pad_gem-1.1.1 lib/foundation/test/template/test.rb
pad_gem-1.1.0 lib/foundation/test/template/test.rb