From 141ce32382d955911b571bf90f065fa364b308f1 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 12 Aug 2014 18:06:47 -0400 Subject: [PATCH] Custom formatter. --- features/support/overview.rb | 183 +++++++++++++++++++++++++++++++++++ script/cibuild | 12 ++- script/cucumber | 10 +- 3 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 features/support/overview.rb diff --git a/features/support/overview.rb b/features/support/overview.rb new file mode 100644 index 00000000..493ef6a6 --- /dev/null +++ b/features/support/overview.rb @@ -0,0 +1,183 @@ +require 'fileutils' +require 'colorator' +require 'cucumber/formatter/console' +require 'cucumber/formatter/io' +require 'gherkin/formatter/escaping' + +module Features + module Support + # The formatter used for --format pretty (the default formatter). + # + # This formatter prints features to plain text - exactly how they were parsed, + # just prettier. That means with proper indentation and alignment of table columns. + # + # If the output is STDOUT (and not a file), there are bright colours to watch too. + # + class Overview + include FileUtils + include Cucumber::Formatter::Console + include Cucumber::Formatter::Io + include Gherkin::Formatter::Escaping + attr_writer :indent + attr_reader :runtime + + def initialize(runtime, path_or_io, options) + @runtime, @io, @options = runtime, ensure_io(path_or_io, "pretty"), options + @exceptions = [] + @indent = 0 + @prefixes = options[:prefixes] || {} + @delayed_messages = [] + end + + def before_features(features) + print_profile_information + end + + def after_features(features) + print_summary(features) + end + + def before_feature(feature) + @exceptions = [] + @indent = 0 + end + + def comment_line(comment_line) + end + + def after_tags(tags) + end + + def tag_name(tag_name) + end + + def before_feature_element(feature_element) + @indent = 2 + @scenario_indent = 2 + end + + def after_feature_element(feature_element) + end + + def before_background(background) + @indent = 2 + @scenario_indent = 2 + @in_background = true + end + + def after_background(background) + @in_background = nil + end + + def background_name(keyword, name, file_colon_line, source_indent) + print_feature_element_name(keyword, name, file_colon_line, source_indent) + end + + def before_examples_array(examples_array) + end + + def examples_name(keyword, name) + end + + def before_outline_table(outline_table) + end + + def after_outline_table(outline_table) + end + + def scenario_name(keyword, name, file_colon_line, source_indent) + print_feature_element_name(keyword, name, file_colon_line, source_indent) + end + + def before_step(step) + @current_step = step + end + + def before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line) + @hide_this_step = false + if exception + if @exceptions.include?(exception) + @hide_this_step = true + return + end + @exceptions << exception + end + if status != :failed && @in_background ^ background + @hide_this_step = true + return + end + @status = status + end + + CHARS = { + :failed => "x".red, + :pending => "?".yellow, + :undefined => "x".red, + :passed => ".".green, + :skipped => "-".blue + } + + def step_name(keyword, step_match, status, source_indent, background, file_colon_line) + @io.print CHARS[status] + end + + def doc_string(string) + return if @options[:no_multiline] || @hide_this_step + s = %{"""\n#{string}\n"""}.indent(@indent) + s = s.split("\n").map{|l| l =~ /^\s+$/ ? '' : l}.join("\n") + @io.puts(format_string(s, @current_step.status)) + @io.flush + end + + def exception(exception, status) + return if @hide_this_step + print_exception(exception, status, @indent) + @io.flush + end + + def before_multiline_arg(multiline_arg) + end + + def after_multiline_arg(multiline_arg) + end + + def before_table_row(table_row) + end + + def after_table_row(table_row) + end + + def after_table_cell(cell) + end + + def table_cell_value(value, status) + end + + private + + def print_feature_element_name(keyword, name, file_colon_line, source_indent) + @io.puts + names = name.empty? ? [name] : name.split("\n") + line = " #{keyword}: #{names[0]}" + if @options[:source] + line_comment = "#{file_colon_line}" + @io.print(line_comment) + end + @io.print(line) + @io.print " " + @io.flush + end + + def cell_prefix(status) + @prefixes[status] + end + + def print_summary(features) + @io.puts + print_stats(features, @options) + print_snippets(@options) + print_passing_wip(@options) + end + end + end +end diff --git a/script/cibuild b/script/cibuild index 24e75c11..d2dd4ae4 100755 --- a/script/cibuild +++ b/script/cibuild @@ -2,5 +2,15 @@ set -e +parallelize_tests() { + ls -1 script/{test,cucumber,proof} | xargs -P 3 -L 1 /bin/bash +} + +serialize_tests() { + script/proof + script/test + script/cucumber +} + script/branding -ls -1 script/{test,cucumber,proof} | xargs -P 3 -L 1 /bin/bash +time parallelize_tests diff --git a/script/cucumber b/script/cucumber index ef19cff4..c6957356 100755 --- a/script/cucumber +++ b/script/cucumber @@ -1,9 +1,5 @@ #!/bin/bash -if test -z "$TRAVIS"; then - PROFILE="--format pretty" -else - PROFILE="--format progress" -fi - -bundle exec cucumber $PROFILE "$@" +time bundle exec cucumber \ + -f Features::Support::Overview \ + "$@"