Last active
December 21, 2015 09:00
-
-
Save foton/d317e1b3371021fee964 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@author: Foton (https://github.com/foton) | |
#this formatter: https://gist.github.com/foton/d317e1b3371021fee964 | |
#Cucumber formatters which displayes only failed steps | |
#usage: cucumber -f Cucumber::Formatter::Failures features/some.feature | |
#usage: cucumber -f Cucumber::Formatter::Failures::OneLine features/some.feature | |
#usage: cucumber -f Cucumber::Formatter::Failures::TwoLines features/some.feature | |
#usage: cucumber -f Cucumber::Formatter::Failures::StacktraceFirst features/some.feature | |
require 'cucumber/formatter/pretty' | |
module Cucumber | |
module Formatter | |
#print only failures with stacktrace in style of pretty (default) formatter | |
class Failures < Cucumber::Formatter::Pretty | |
#turning off all unwanted outputs | |
def before_features(features); end | |
def after_features(features); end | |
def comment_line(comment_line); end | |
def tag_name(tag_name); end | |
def feature_name(keyword, name); end | |
def after_feature_element(feature_element); end | |
def after_background(background); end | |
def background_name(keyword, name, file_colon_line, source_indent); end | |
def before_examples_array(examples_array); end | |
def examples_name(keyword, name); end | |
def scenario_name(keyword, name, file_colon_line, source_indent); end | |
def step_name(keyword, step_match, status, source_indent, background, file_colon_line); end | |
def before_table_row(table_row) | |
return if !@table || @hide_this_step | |
@col_index = 0 | |
end | |
def after_table_row(table_row); end | |
def table_cell_value(value, status); end | |
# append summary at beginging of file | |
def after_features(features) | |
print_summary(features) | |
end | |
private | |
def print_summary(features) | |
@io.puts | |
@io.puts("Summary of CUCUMBER tests:") | |
print_stats(features, @options) | |
print_snippets(@options) | |
print_passing_wip(@options) | |
end | |
def print_exception(e, status, indent) | |
message = "#{e.message} (#{e.class})" | |
if ENV['CUCUMBER_TRUNCATE_OUTPUT'] | |
message = linebreaks(message, ENV['CUCUMBER_TRUNCATE_OUTPUT'].to_i) | |
end | |
string = "#{message}\n#{e.backtrace.join("\n")}".indent(indent) | |
@io.puts(format_string(string, status)) | |
end | |
end | |
#print whole failure to 1 line | |
class Failures::OneLine < Failures | |
def print_exception(e, status, indent) | |
message = "#{e.message} (#{e.class})" | |
string = "[#{e.backtrace.reverse.join(" >> ")}] #{message}\n" | |
@io.puts(format_string(string, status)) | |
end | |
end | |
#print whole failure to 2 lines (stacktrace + message) | |
class Failures::TwoLines < Failures | |
def print_exception(e, status, indent) | |
message = "#{e.message} (#{e.class})" | |
string = "[#{e.backtrace.reverse.join(" >> ")}]\n#{message}\n" | |
@io.puts(format_string(string, status)) | |
end | |
end | |
#like pretty format but stacktrace is first(and reversed), then is message | |
class Failures::StacktraceFirst < Failures | |
def print_exception(e, status, indent) | |
message = "#{e.message} (#{e.class})" | |
string = "#{e.backtrace.reverse.join("\n")}\n#{message}" | |
@io.puts(format_string(string, status)) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment