class XCPretty::HTML

Constants

FILEPATH
SCREENSHOT_DIR
TEMPLATE

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/xcpretty/reporters/html.rb, line 17
def initialize(options)
  super(options)
  @test_suites = {}
  @collect_screenshots = options[:screenshots]
end

Public Instance Methods

format_failing_test(suite, test_case, reason, file) click to toggle source
# File lib/xcpretty/reporters/html.rb, line 27
def format_failing_test(suite, test_case, reason, file)
  add_test(suite, name: test_case, failing: true,
                  reason: reason, file: file,
                  snippet: formatted_snippet(file),
                  screenshots: [])
end
format_passing_test(suite, test_case, time) click to toggle source
# File lib/xcpretty/reporters/html.rb, line 34
def format_passing_test(suite, test_case, time)
  add_test(suite, name: test_case, time: time, screenshots: [])
end
handle(line) click to toggle source
# File lib/xcpretty/reporters/html.rb, line 23
def handle(line)
  @parser.parse(line)
end
load_dependencies() click to toggle source
# File lib/xcpretty/reporters/html.rb, line 8
def load_dependencies
  unless @@loaded ||= false
    require 'fileutils'
    require 'pathname'
    require 'erb'
    @@loaded = true
  end
end

Private Instance Methods

add_test(suite_name, data) click to toggle source
# File lib/xcpretty/reporters/html.rb, line 45
def add_test(suite_name, data)
  @test_count += 1
  @test_suites[suite_name] ||= {tests: []}
  @test_suites[suite_name][:tests] << data
  if data[:failing]
    @test_suites[suite_name][:failing] = true
    @fail_count += 1
  end
end
find_test(image_name) click to toggle source
# File lib/xcpretty/reporters/html.rb, line 80
def find_test(image_name)
  @test_suites.each do |name, info|
    info[:tests].each do |test, index|
      combined_name = name + '_' + test[:name]
      test_name_matches = image_name.start_with?(test[:name])
      combined_name_matches = image_name.start_with?(combined_name)
      return test if test_name_matches || combined_name_matches
    end
  end
  nil
end
formatted_snippet(filepath) click to toggle source
# File lib/xcpretty/reporters/html.rb, line 40
def formatted_snippet(filepath)
  snippet = Snippet.from_filepath(filepath)
  Syntax.highlight_html(snippet)
end
load_screenshots() click to toggle source
# File lib/xcpretty/reporters/html.rb, line 69
def load_screenshots
  Dir.foreach(SCREENSHOT_DIR) do |item|
    next if item == '.' || item == '..' || File.extname(item) != '.png'

    test = find_test(item)
    next if test.nil?

    test[:screenshots] << item
  end
end
write_report() click to toggle source
# File lib/xcpretty/reporters/html.rb, line 55
def write_report
  if @collect_screenshots
    load_screenshots
  end
  File.open(@filepath, 'w') do |f|
    # WAT: get rid of these locals. BTW Cucumber fails if you remove them
    test_suites = @test_suites
    fail_count  = @fail_count
    test_count  = @test_count
    erb = ERB.new(File.open(TEMPLATE, 'r').read)
    f.write erb.result(binding)
  end
end