class UglyFace::Formatter::Html

Attributes

report[R]

Public Class Methods

new(step_mother, path_or_io, options) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 24
def initialize(step_mother, path_or_io, options)
  @path = path_or_io
  set_path_and_file(path_or_io)
  @path_to_erb = File.join(File.dirname(__FILE__), '..', 'templates')
  @step_mother = step_mother
  @options = options
  # The expand option is set to true by RubyMine and cannot be turned off using the IDE. This option causes
  # a test run while using this gem to terminate.
  @options[:expand] = false unless @options.nil?
  @report = Report.new
  @img_id = 0
  @logo = 'logo.png'
  @delayed_messages = []
end

Public Instance Methods

after_background(background) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 84
def after_background(background)
  @report.end_background
  @report.current_feature.background << ReportStep.new(background)
end
after_feature(feature) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 76
def after_feature(feature)
  @report.current_feature.close(feature)
end
after_feature_element(feature_element) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 95
def after_feature_element(feature_element)
#  unless scenario_outline?(feature_element)
    process_scenario(feature_element)
#  end
end
after_features(features) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 126
def after_features(features)
  @features = features
  @duration = format_duration(Time.now - @tests_started)
  copy_images
  copy_stylesheets
  generate_report
end
after_step(step) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 118
def after_step(step)
  step = process_step(step) unless step_belongs_to_outline? step
  if @cells
    step.table = @cells
    @cells = nil
  end
end
after_table_row(example_row) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 106
def after_table_row(example_row)
  unless info_row?(example_row)
    @report.current_scenario.populate(example_row)
    build_scenario_outline_steps(example_row)
  end
  populate_cells(example_row) if example_row.instance_of? Cucumber::Core::Ast::DataTable
end
before_background(background) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 80
def before_background(background)
  @report.begin_background
end
before_feature(feature) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 72
def before_feature(feature)
  @report.add_feature ReportFeature.new(feature, features_summary_file)
end
before_feature_element(feature_element) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 89
def before_feature_element(feature_element)
#  unless scenario_outline? feature_element
    @report.add_scenario  ReportScenario.new(feature_element)
#  end
end
before_features(features) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 62
def before_features(features)
  make_output_directories
  @tests_started = Time.now
end
before_step(step) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 114
def before_step(step)
  @step_timer = Time.now
end
before_table_row(example_row) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 101
def before_table_row(example_row)
  @before_example_row = example_row
  @report.add_scenario ReportScenario.new(example_row) unless info_row?(example_row)
end
custom_feature_header?() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 147
def custom_feature_header?
  return false unless customization_directory

  Dir.foreach(customization_directory) do |file|
    return true if file == '_feature_header.erb'
  end
  false
end
custom_suite_header?() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 138
def custom_suite_header?
  return false unless customization_directory

  Dir.foreach(customization_directory) do |file|
    return true if file == '_suite_header.erb'
  end
  false
end
embed(src, mime_type, label) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 46
def embed(src, mime_type, label)
  case(mime_type)
  when /^image\/(png|gif|jpg|jpeg)/
    embed_image(src, label)
  end
end
embed_image(src, label) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 53
def embed_image(src, label)
  @report.current_scenario.image << src.split(separator).last
  @report.current_scenario.image_label << label
  @report.current_scenario.image_id << "img_#{@img_id}"
  @img_id += 1
  filename = "#{File.dirname(@path)}#{separator}images"
  FileUtils.cp src, filename
end
features() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 134
def features
  @report.features
end
features_summary_file() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 67
def features_summary_file
  parts = @io.path.split(separator)
  parts[parts.length - 1]
end
set_path_and_file(path_or_io) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 39
def set_path_and_file(path_or_io)
  return if path_or_io.nil?
  dir = File.dirname(path_or_io)
  FileUtils.mkdir_p dir unless File.directory? dir
  @io = ensure_io(path_or_io)
end

Private Instance Methods

build_scenario_outline_steps(example_row) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 261
      def build_scenario_outline_steps(example_row)
        si = example_row.cells
        si.each do |row|
          duration =  Time.now - @step_timer
          report_step = ReportStep.new(@before_example_row, example_row)
          report_step.duration = duration
          @report.add_step report_step
#          process_step(row, row.status)
        end
      end
copy_directory(dir, file_names, file_extension) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 192
def copy_directory(dir, file_names, file_extension)
  path = "#{File.dirname(@path)}#{separator}#{dir}"
  file_names.each do |file|
    copy_file File.join(File.dirname(__FILE__), '..', 'templates', "#{file}.#{file_extension}"), path
  end
end
copy_file(source, destination) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 199
def copy_file(source, destination)
  FileUtils.cp source, destination
end
copy_images() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 203
def copy_images
  copy_directory 'images', %w(debug screenshot failed passed pending undefined skipped table_failed table_passed table_pending table_undefined table_skipped), "png"
  logo = logo_file
  copy_file logo, "#{File.join(File.dirname(@path), 'images')}" if logo
  copy_directory 'images', ['logo'], 'png' unless logo
end
copy_stylesheets() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 210
def copy_stylesheets
  copy_directory 'stylesheets', ['style'], 'css'
end
customization_directory() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 224
def customization_directory
  dir = File.join(File.expand_path('features'), 'support', 'ugly_face')
  return dir if File.exists? dir
end
generate_report() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 158
def generate_report
  paths = [@path_to_erb, customization_directory.to_s]
  renderer = ActionView::Base.new(paths)
  filename = File.join(@path_to_erb, 'main')
  @io.puts renderer.render(:file => filename, :locals => {:report => self, :logo => @logo})
  features.each do |feature|
    write_feature_file(feature)
  end
end
info_row?(example_row) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 250
def info_row?(example_row)
  return example_row.scenario_outline.nil? if example_row.respond_to? :scenario_outline
  return true if example_row.instance_of? Cucumber::Formatter::LegacyApi::Ast::DataTableRow
  false
end
logo_file() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 214
def logo_file
  dir = customization_directory
  Dir.foreach(dir) do |file|
    if file =~ /^logo\.(png|gif|jpg|jpeg)$/
      @logo = file
      return File.join(dir, file)
    end
  end if dir
end
make_directory(dir) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 187
def make_directory(dir)
  path = "#{File.dirname(@path)}#{separator}#{dir}"
  FileUtils.mkdir_p path unless File.directory? path
end
make_output_directories() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 182
def make_output_directories
  make_directory 'images'
  make_directory 'stylesheets'
end
populate_cells(example_row) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 276
def populate_cells(example_row)
  @cells ||= []
  values = []
  example_row.to_a.each do |cell|
    values << cell.value
  end
  @cells << values
end
process_scenario(scenario) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 229
def process_scenario(scenario)
  @report.current_scenario.populate(scenario)
end
process_step(step, status=nil) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 233
def process_step(step, status=nil)
  duration =  Time.now - @step_timer
  report_step = ReportStep.new(step)
  report_step.duration = duration
  report_step.status = status unless status.nil?
  if step.background
    @report.current_feature.background << report_step if @report.processing_background_steps?
  else
    @report.add_step report_step
  end
  report_step
end
scenario_outline?(feature_element) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 246
def scenario_outline?(feature_element)
  feature_element.is_a? Cucumber::Core::Ast::ScenarioOutline
end
separator() click to toggle source
# File lib/ugly_face/formatter/html.rb, line 285
def separator
  File::ALT_SEPARATOR || File::SEPARATOR
end
step_belongs_to_outline?(step) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 256
def step_belongs_to_outline?(step)
  scenario = step.instance_variable_get "@feature_element"
  not scenario.nil?
end
step_error(exception) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 271
def step_error(exception)
  return nil if exception.nil?
  exception.backtrace[-1] =~ /^#{step.file_colon_line}/ ? exception : nil
end
write_feature_file(feature) click to toggle source
# File lib/ugly_face/formatter/html.rb, line 168
def write_feature_file(feature)
  paths = [@path_to_erb, customization_directory.to_s]
  renderer = ActionView::Base.new(paths)
  filename = File.join(@path_to_erb, 'feature')
  output_file = "#{File.dirname(@path)}#{separator}#{feature.file}"
  to_cut = output_file.split(separator).last
  directory = output_file.sub("#{separator}#{to_cut}", '')
  FileUtils.mkdir_p directory unless File.directory? directory
  file = File.new(output_file, Cucumber.file_mode('w'))
  file.puts renderer.render(:file => filename, :locals => {:feature => feature, :logo => @logo, :customize => custom_feature_header?})
  file.flush
  file.close
end