Class: PrettyFace::Formatter::Html

Inherits:
Object
  • Object
show all
Includes:
Cucumber::Formatter::Duration, Cucumber::Formatter::Io, ViewHelper
Defined in:
lib/pretty_face/formatter/html.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ViewHelper

#failed_scenario?, #scenario_average_duration, #scenario_count, #scenarios_summary_for, #start_time, #step_average_duration, #step_count, #steps_summary_for, #total_duration

Constructor Details

#initialize(step_mother, path_or_io, options) ⇒ Html

Returns a new instance of Html.



21
22
23
24
25
26
27
28
29
30
# File 'lib/pretty_face/formatter/html.rb', line 21

def initialize(step_mother, path_or_io, options)
  @path = path_or_io
  @io = ensure_io(path_or_io, 'html')
  @path_to_erb = File.join(File.dirname(__FILE__), '..', 'templates')
  @step_mother = step_mother
  @options = options
  @report = Report.new
  @img_id = 0
   = 'face.png'
end

Instance Attribute Details

#logoObject (readonly)

Returns the value of attribute logo.



19
20
21
# File 'lib/pretty_face/formatter/html.rb', line 19

def 
  
end

#reportObject (readonly)

Returns the value of attribute report.



19
20
21
# File 'lib/pretty_face/formatter/html.rb', line 19

def report
  @report
end

Instance Method Details

#after_background(background) ⇒ Object



69
70
71
72
# File 'lib/pretty_face/formatter/html.rb', line 69

def after_background(background)
  @report.end_background
  @report.current_feature.background << ReportStep.new(background)
end

#after_feature(feature) ⇒ Object



61
62
63
# File 'lib/pretty_face/formatter/html.rb', line 61

def after_feature(feature)
  @report.current_feature.close(feature)
end

#after_feature_element(feature_element) ⇒ Object



80
81
82
83
84
# File 'lib/pretty_face/formatter/html.rb', line 80

def after_feature_element(feature_element)
  unless scenario_outline?(feature_element)
    process_scenario(feature_element)
  end
end

#after_features(features) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/pretty_face/formatter/html.rb', line 110

def after_features(features)
  @features = features
  @duration = format_duration(Time.now - @tests_started)
  copy_images
  copy_stylesheets
  generate_report
end

#after_step(step) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/pretty_face/formatter/html.rb', line 102

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) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/pretty_face/formatter/html.rb', line 90

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::Ast::Table::Cells
end

#before_background(background) ⇒ Object



65
66
67
# File 'lib/pretty_face/formatter/html.rb', line 65

def before_background(background)
  @report.begin_background
end

#before_feature(feature) ⇒ Object



57
58
59
# File 'lib/pretty_face/formatter/html.rb', line 57

def before_feature(feature)
  @report.add_feature ReportFeature.new(feature, features_summary_file)
end

#before_feature_element(feature_element) ⇒ Object



74
75
76
77
78
# File 'lib/pretty_face/formatter/html.rb', line 74

def before_feature_element(feature_element)
  unless scenario_outline? feature_element
    @report.add_scenario  ReportScenario.new(feature_element)
  end
end

#before_features(features) ⇒ Object



47
48
49
50
# File 'lib/pretty_face/formatter/html.rb', line 47

def before_features(features)
  make_output_directories
  @tests_started = Time.now
end

#before_step(step) ⇒ Object



98
99
100
# File 'lib/pretty_face/formatter/html.rb', line 98

def before_step(step)
  @step_timer = Time.now
end

#before_table_row(example_row) ⇒ Object



86
87
88
# File 'lib/pretty_face/formatter/html.rb', line 86

def before_table_row(example_row)
  @report.add_scenario ReportScenario.new(example_row) unless info_row?(example_row)
end

#custom_feature_header?Boolean

Returns:

  • (Boolean)


131
132
133
134
135
136
137
138
# File 'lib/pretty_face/formatter/html.rb', line 131

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?Boolean

Returns:

  • (Boolean)


122
123
124
125
126
127
128
129
# File 'lib/pretty_face/formatter/html.rb', line 122

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) ⇒ Object



32
33
34
35
36
37
# File 'lib/pretty_face/formatter/html.rb', line 32

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) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/pretty_face/formatter/html.rb', line 39

def embed_image(src, label)
  @report.current_scenario.image = src.split('/').last
  @report.current_scenario.image_label = label
  @report.current_scenario.image_id = "img_#{@img_id}"
  @img_id += 1
  FileUtils.cp src, "#{File.dirname(@path)}/images"
end

#featuresObject



118
119
120
# File 'lib/pretty_face/formatter/html.rb', line 118

def features
  @report.features
end

#features_summary_fileObject



52
53
54
55
# File 'lib/pretty_face/formatter/html.rb', line 52

def features_summary_file
  parts = @io.path.split('/')
  parts[parts.length - 1]
end