Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/pretty_face.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,26 @@
require "pretty_face/formatter/html"

module PrettyFace
# Your code goes here...

@msg_storage= Array.new

def self.set_header(data)
data_2= Hash.new
data.each { |k, v| (data_2.length >= data.length) ? break : data_2[:"#{k}"]= data.delete(k) }
@header_row_1= data
@header_row_2= data_2
end

def self.get_header(row)
(row == 1) ? @header_row_1 : @header_row_2
end

def self.log_scenario_msg(data)
@msg_storage.push(data)
end

def self.fetch_scenario_msg
@msg_storage.shift
end

end
48 changes: 23 additions & 25 deletions lib/pretty_face/formatter/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
require 'fileutils'
require 'cucumber/formatter/io'
require 'cucumber/formatter/duration'
require 'cucumber/core/ast/scenario'
require 'cucumber/multiline_argument/data_table'

require 'cucumber/formatter/console'
require 'cucumber/ast/scenario'
require 'cucumber/ast/table'
require 'cucumber/ast/outline_table'
require File.join(File.dirname(__FILE__), 'view_helper')
require File.join(File.dirname(__FILE__), 'report')

Expand All @@ -18,6 +19,7 @@ module Formatter
class Html
include Cucumber::Formatter::Io
include Cucumber::Formatter::Duration
include Cucumber::Formatter::Console
include ViewHelper

attr_reader :report, :logo
Expand All @@ -33,7 +35,8 @@ def initialize(step_mother, path_or_io, options)
@options[:expand] = false unless @options.nil?
@report = Report.new
@img_id = 0
@logo = 'face.png'
@logo = 'logo.png'
@delayed_messages = []
end

def set_path_and_file(path_or_io)
Expand All @@ -42,11 +45,11 @@ def set_path_and_file(path_or_io)
FileUtils.mkdir_p dir unless File.directory? dir
@io = ensure_io(path_or_io, 'html')
end

def embed(src, mime_type, label)
case(mime_type)
when /^image\/(png|gif|jpg|jpeg)/
embed_image(src, label)
when /^image\/(png|gif|jpg|jpeg)/
embed_image(src, label)
end
end

Expand Down Expand Up @@ -87,19 +90,18 @@ def after_background(background)
end

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

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

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

Expand All @@ -108,7 +110,7 @@ def after_table_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
populate_cells(example_row) if example_row.instance_of? Cucumber::Ast::Table::Cells
end

def before_step(step)
Expand Down Expand Up @@ -201,10 +203,10 @@ def copy_file(source, destination)
end

def copy_images
copy_directory 'images', %w(failed passed pending undefined skipped table_failed table_passed table_pending table_undefined table_skipped), "png"
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', ['face'], 'png' unless logo
copy_directory 'images', ['logo'], 'png' unless logo
end

def copy_stylesheets
Expand All @@ -222,7 +224,7 @@ def logo_file
end

def customization_directory
dir = File.join(File.expand_path('features'), 'support', 'pretty_face')
dir = File.join(File.expand_path('features'), 'support', 'ugly_face')
return dir if File.exists? dir
end

Expand All @@ -235,7 +237,7 @@ def process_step(step, status=nil)
report_step = ReportStep.new(step)
report_step.duration = duration
report_step.status = status unless status.nil?
if step.background
if step.background?
@report.current_feature.background << report_step if @report.processing_background_steps?
else
@report.add_step report_step
Expand All @@ -244,12 +246,12 @@ def process_step(step, status=nil)
end

def scenario_outline?(feature_element)
feature_element.is_a? Cucumber::Core::Ast::ScenarioOutline
feature_element.is_a? Cucumber::Ast::ScenarioOutline
end

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
return true if example_row.instance_of? Cucumber::Ast::Table::Cells
false
end

Expand All @@ -259,13 +261,9 @@ def step_belongs_to_outline?(step)
end

def build_scenario_outline_steps(example_row)
si = example_row.cells
si = example_row.instance_variable_get :@step_invocations
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)
process_step(row, row.status)
end
end

Expand Down
45 changes: 20 additions & 25 deletions lib/pretty_face/formatter/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,13 @@ def step_summary_for(status)
end

def scenario_average_duration
has_duration = scenarios.reject { |scenario| scenario.duration.nil? }
durations = has_duration.collect { |scenario| scenario.duration }
durations = scenarios.collect { |scenario| scenario.duration }
formatted_duration(durations.reduce(:+).to_f / durations.size)
end

def step_average_duration
steps = scenarios.collect { |scenario| scenario.steps }
has_duration = steps.flatten.reject { |step| step.duration.nil? }
durations = has_duration.collect { |step| step.duration }
durations = steps.flatten.collect { |step| step.duration }
formatted_duration(durations.reduce(:+).to_f / durations.size)
end

Expand Down Expand Up @@ -173,17 +171,17 @@ def initialize(scenario)
@image_id = []
@start = Time.now
end

def populate(scenario)
@duration = Time.now - @start
@status = scenario.status
if scenario.instance_of? Cucumber::Formatter::LegacyApi::Ast::Scenario
if scenario.instance_of? Cucumber::Ast::Scenario
@name = scenario.name
@file_colon_line = scenario.line
elsif scenario.instance_of? Cucumber::Formatter::LegacyApi::Ast::ExampleTableRow
@name = scenario.name
@file_colon_line = scenario.line
@file_colon_line = scenario.file_colon_line
elsif scenario.instance_of? Cucumber::Ast::OutlineTable::ExampleRow
@name = scenario.scenario_outline.name
@file_colon_line = scenario.backtrace_line
end
@status = scenario.status
end

def has_image?
Expand All @@ -194,22 +192,19 @@ def has_image?
class ReportStep
attr_accessor :name, :keyword, :file_colon_line, :status, :duration, :table, :multiline_arg, :error

def initialize(step, ast_step=nil)
if ast_step
@name = ast_step.name
@keyword = ast_step.keyword
@status = ast_step.status
@error = ast_step.exception
else
@name = step.name
unless step.instance_of? Cucumber::Formatter::LegacyApi::Ast::Background
def initialize(step)
@name = step.name
@file_colon_line = step.file_colon_line
unless step.instance_of? Cucumber::Ast::Background
if step.respond_to? :actual_keyword
@keyword = step.actual_keyword
else
@keyword = step.keyword
@status = step.status
@multiline_arg = step.multiline_arg unless step.multiline_arg.instance_of? Cucumber::Core::Ast::EmptyMultilineArgument
@error = step.exception
end
@status = step.status
@multiline_arg = step.multiline_arg
@error = step.exception
end
@file_colon_line = step.file_colon_line
end

def failed_with_error?
Expand Down Expand Up @@ -254,7 +249,7 @@ def snippet(error)
end

def snippet_for(error_line)
file, line = file_name_and_line(error_line)
file, line = file_name_and_line(error_line)
if file
[lines_around(file, line), line, file]
else
Expand Down
10 changes: 4 additions & 6 deletions lib/pretty_face/formatter/view_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'cucumber/core/ast/scenario_outline'
require 'cucumber/ast/scenario_outline'

module PrettyFace
module UglyFace
module Formatter
module ViewHelper

Expand All @@ -23,15 +23,13 @@ def total_duration
def step_average_duration(features)
scenarios = features.collect { |feature| feature.scenarios }
steps = scenarios.flatten.collect { |scenario| scenario.steps }
has_duration = steps.flatten.reject { |step| step.duration.nil? }
durations = has_duration.collect { |step| step.duration }
durations = steps.flatten.collect { |step| step.duration }
format_duration get_average_from_float_array durations
end

def scenario_average_duration(features)
scenarios = features.collect { |feature| feature.scenarios }
has_duration = scenarios.flatten.reject { |scenario| scenario.duration.nil? }
durations = has_duration.collect { |scenario| scenario.duration }
durations = scenarios.flatten.collect { |scenario| scenario.duration }
format_duration get_average_from_float_array durations
end

Expand Down
71 changes: 32 additions & 39 deletions lib/pretty_face/templates/_step.erb
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
<%= "#{step.keyword} #{step.name}" %>
<% if step.has_table? %>
<br />
<table border="1" class="param_table">
<tr>
<% step.table.first.each do |column| %>
<th><%= column %></th>
<br />
<table border="1" class="param_table">
<% step.table.each do |row| %>
<tr>
<% row.each_with_index do |column, index| %>
<% if index == 0 %>
<th><%= column %></th>
<% else %>
<td><%= column %></td>
<% end %>
<% end %>
</tr>
<% end %>
</tr>
<% step.table.delete_at 0 %>
<% step.table.each do |row| %>
<tr>
<% row.each do |column| %>
<td><%= column %></td>
<% end %>
</tr>
<% end %>
</table>
</table>
<% end %>
<% if step.has_multiline_arg? %>
<br />
<table border="1" class="multiline_arg">
<tr>
<td><pre><%= step.multiline_arg %></pre></td>
</tr>
</table>
<br />
<table border="1" class="multiline_arg">
<tr>
<td><pre><%= step.multiline_arg %></pre></td>
</tr>
</table>
<% end %>
<% if step.failed_with_error? %>
<table>
<tr class="error">
<td class="message">
<strong><pre><%= "#{step.error.message} (#{step.error.class})" %></pre></strong>
</td>
</tr>
<tr>
<td>
<%= raw(step.extra_failure_content(step.error.backtrace)) %>
</td>
</tr>
<tr >
<td class="detail">
<pre><%= step.error.backtrace.join("\n") %></pre>
</td>
</tr>
</table>
<% end %>
<table>
<tr class="error">
<td class="message">
<strong><pre><%= "#{step.error.message} (#{step.error.class})" %></pre></strong>
</td>
</tr>
<tr>
<td>
<%= raw(step.extra_failure_content(step.error.backtrace)) %>
</td>
</tr>
</table>
<% end %>
Loading