Rearrange Cucumber and add some flair.
* Move step_definitions/jekyll.rb to just step_definitions.rb * Rename the formatter to Jekyll::Cucumber::Formatter, it's Jekyll's. * Add some flair; switch to checks! * Rename env.rb to helpers.rb
This commit is contained in:
parent
597021a813
commit
c5b8b3315f
|
@ -3,142 +3,176 @@ require 'colorator'
|
|||
require 'cucumber/formatter/console'
|
||||
require 'cucumber/formatter/io'
|
||||
|
||||
module Features
|
||||
module Support
|
||||
# The formatter used for <tt>--format pretty</tt> (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
|
||||
module Jekyll
|
||||
module Cucumber
|
||||
class Formatter
|
||||
attr_accessor :indent, :runtime
|
||||
include ::Cucumber::Formatter::Console
|
||||
include ::Cucumber::Formatter::Io
|
||||
include FileUtils
|
||||
include Cucumber::Formatter::Console
|
||||
include Cucumber::Formatter::Io
|
||||
attr_writer :indent
|
||||
attr_reader :runtime
|
||||
|
||||
CHARS = {
|
||||
:failed => "\u2718".red,
|
||||
:pending => "\u203D".yellow,
|
||||
:undefined => "\u2718".red,
|
||||
:passed => "\u2714".green,
|
||||
:skipped => "\u203D".blue
|
||||
}
|
||||
|
||||
#
|
||||
|
||||
def initialize(runtime, path_or_io, options)
|
||||
@runtime, @io, @options = runtime, ensure_io(path_or_io), options
|
||||
@exceptions = []
|
||||
@indent = 0
|
||||
@runtime = runtime
|
||||
@snippets_input = []
|
||||
@io = ensure_io(path_or_io)
|
||||
@prefixes = options[:prefixes] || {}
|
||||
@delayed_messages = []
|
||||
@snippets_input = []
|
||||
@options = options
|
||||
@exceptions = []
|
||||
@indent = 0
|
||||
end
|
||||
|
||||
#
|
||||
|
||||
def before_features(features)
|
||||
print_profile_information
|
||||
end
|
||||
|
||||
#
|
||||
|
||||
def after_features(features)
|
||||
@io.puts
|
||||
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 comment_line(comment_line); end
|
||||
def after_feature_element(feature_element); 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
|
||||
@indent = 2
|
||||
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)
|
||||
#
|
||||
|
||||
def background_name(keyword, name, source_line, indend)
|
||||
print_feature_element_name(
|
||||
keyword, name, source_line, indend
|
||||
)
|
||||
end
|
||||
|
||||
def scenario_name(keyword, name, file_colon_line, source_indent)
|
||||
print_feature_element_name(keyword, name, file_colon_line, source_indent)
|
||||
#
|
||||
|
||||
def scenario_name(keyword, name, source_line, indent)
|
||||
print_feature_element_name(
|
||||
keyword, name, source_line, 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)
|
||||
#
|
||||
|
||||
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]
|
||||
@io.print " "
|
||||
end
|
||||
|
||||
#
|
||||
|
||||
def exception(exception, status)
|
||||
return if @hide_this_step
|
||||
|
||||
@io.puts
|
||||
print_exception(exception, status, @indent)
|
||||
@io.flush
|
||||
end
|
||||
|
||||
#
|
||||
|
||||
def after_test_step(test_step, result)
|
||||
collect_snippet_data(test_step, result)
|
||||
collect_snippet_data(
|
||||
test_step, result
|
||||
)
|
||||
end
|
||||
|
||||
#
|
||||
|
||||
private
|
||||
|
||||
def print_feature_element_name(keyword, name, file_colon_line, source_indent)
|
||||
def print_feature_element_name(keyword, name, source_line, indent)
|
||||
@io.puts
|
||||
names = name.empty? ? [name] : name.split("\n")
|
||||
|
||||
names = name.empty? ? [name] : name.each_line.to_a
|
||||
line = " #{keyword}: #{names[0]}"
|
||||
if @options[:source]
|
||||
line_comment = "#{file_colon_line}"
|
||||
@io.print(line_comment)
|
||||
end
|
||||
|
||||
@io.print(source_line) if @options[:source]
|
||||
@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)
|
|
@ -1,11 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if ruby --version | grep -q "jruby"
|
||||
then
|
||||
echo "Move along, we are not testing features on JRuby right now."
|
||||
exit 0
|
||||
else
|
||||
time ruby -S bundle exec cucumber \
|
||||
-f Features::Support::Overview \
|
||||
"$@"
|
||||
fi
|
||||
time ruby -S bundle exec cucumber \
|
||||
-f Jekyll::Cucumber::Formatter "$@"
|
||||
|
|
Loading…
Reference in New Issue