class PrettyFace::Formatter::Html
Attributes
logo[R]
report[R]
Public Class Methods
new(step_mother, path_or_io, options)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 25 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 = 'face.png' end
Public Instance Methods
after_background(background)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 93 def after_background(background) @report.end_background @report.current_feature.background << ReportStep.new(background) end
after_feature(feature)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 85 def after_feature(feature) @report.current_feature.close(feature) end
after_feature_element(feature_element)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 104 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/pretty_face/formatter/html.rb, line 134 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/pretty_face/formatter/html.rb, line 126 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/pretty_face/formatter/html.rb, line 114 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)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 89 def before_background(background) @report.begin_background end
before_feature(feature)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 81 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/pretty_face/formatter/html.rb, line 98 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/pretty_face/formatter/html.rb, line 71 def before_features(features) make_output_directories @tests_started = Time.now end
before_step(step)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 122 def before_step(step) @step_timer = Time.now end
before_table_row(example_row)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 110 def before_table_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/pretty_face/formatter/html.rb, line 155 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/pretty_face/formatter/html.rb, line 146 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/pretty_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/pretty_face/formatter/html.rb, line 53 def embed_image(src, label) report_image = ReportImage.new report_image.src = src report_image.label = label report_image.id = "img_#{@img_id}" @img_id += 1 # only copy an image if we have to unless src =~ /^data:/ report_image.src = src.split(separator).last filename = "#{File.dirname(@path)}#{separator}images" FileUtils.cp src, filename end @report.current_scenario.images << report_image end
features()
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 142 def features @report.features end
features_summary_file()
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 76 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/pretty_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, 'html') end
Private Instance Methods
build_scenario_outline_steps(example_row)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 269 def build_scenario_outline_steps(example_row) si = example_row.instance_variable_get :@step_invocations si.each do |row| process_step(row, row.status) end end
copy_directory(dir, file_names, file_extension)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 200 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/pretty_face/formatter/html.rb, line 207 def copy_file(source, destination) FileUtils.cp source, destination end
copy_images()
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 211 def copy_images copy_directory 'images', %w(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', ['face'], 'png' unless logo end
copy_stylesheets()
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 218 def copy_stylesheets copy_directory 'stylesheets', ['style'], 'css' end
customization_directory()
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 232 def customization_directory dir = File.join(File.expand_path('features'), 'support', 'pretty_face') return dir if File.exists? dir end
generate_report()
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 166 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/pretty_face/formatter/html.rb, line 258 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::Ast::Table::Cells false end
logo_file()
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 222 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/pretty_face/formatter/html.rb, line 195 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/pretty_face/formatter/html.rb, line 190 def make_output_directories make_directory 'images' make_directory 'stylesheets' end
populate_cells(example_row)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 281 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/pretty_face/formatter/html.rb, line 237 def process_scenario(scenario) @report.current_scenario.populate(scenario) end
process_step(step, status=nil)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 241 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/pretty_face/formatter/html.rb, line 254 def scenario_outline?(feature_element) feature_element.is_a? Cucumber::Ast::ScenarioOutline end
separator()
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 290 def separator File::ALT_SEPARATOR || File::SEPARATOR end
step_belongs_to_outline?(step)
click to toggle source
# File lib/pretty_face/formatter/html.rb, line 264 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/pretty_face/formatter/html.rb, line 276 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/pretty_face/formatter/html.rb, line 176 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