Sha256: 8188e5263a3bfc5ac20faceca5f0b96e20c7835fbadfb6b2f1f411b83a0453e6

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

require 'oopsy'
require 'pathname'

class Example

  attr_reader :description, :full_description, :run_time, :duration, :status,
              :exception, :file_path, :metadata, :spec

  def initialize(example, report_folder)
    @description = example.description
    @full_description = example.full_description
    @execution_result = example.execution_result
    @metadata = example.metadata
    @file_path = @metadata[:file_path]
    @exception = Oopsy.new(example.exception, @file_path)
    @spec = nil
    @report_folder = report_folder
  end

  def has_exception?
    !@exception.klass.nil?
  end

  def has_spec?
    !@spec.nil?
  end

  def set_spec(spec)
    @spec = spec
  end

  def klass(prefix = 'label-')
    class_map = { passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning" }
    class_map[status.to_sym]
  end

  def screenshot
    return nil unless @metadata[:screenshot]

    unless File.exist?(@metadata[:screenshot])
      puts "The screenshot '#{@metadata[:screenshot]}' does not exist"
    end

    report_dir = Pathname.new(File.expand_path(File.dirname(@report_folder)))
    screenshot = Pathname.new(File.expand_path(@metadata[:screenshot]))
    screenshot.relative_path_from(report_dir).to_s
  end

  def run_time
    (@execution_result.run_time).round(5)
  end

  def duration
    @execution_result.run_time.to_s(:rounded, precision: 5)
  end
  def status
    @execution_result.status.to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec_yah_formatter-0.0.8 lib/example.rb
rspec_yah_formatter-0.0.7 lib/example.rb