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:
Jordon Bedwell 2016-01-11 14:55:34 -06:00
parent 597021a813
commit c5b8b3315f
4 changed files with 84 additions and 57 deletions

View File

@ -3,142 +3,176 @@ require 'colorator'
require 'cucumber/formatter/console' require 'cucumber/formatter/console'
require 'cucumber/formatter/io' require 'cucumber/formatter/io'
module Features module Jekyll
module Support module Cucumber
# The formatter used for <tt>--format pretty</tt> (the default formatter). class Formatter
# attr_accessor :indent, :runtime
# This formatter prints features to plain text - exactly how they were parsed, include ::Cucumber::Formatter::Console
# just prettier. That means with proper indentation and alignment of table columns. include ::Cucumber::Formatter::Io
#
# If the output is STDOUT (and not a file), there are bright colours to watch too.
#
class Overview
include FileUtils include FileUtils
include Cucumber::Formatter::Console
include Cucumber::Formatter::Io CHARS = {
attr_writer :indent :failed => "\u2718".red,
attr_reader :runtime :pending => "\u203D".yellow,
:undefined => "\u2718".red,
:passed => "\u2714".green,
:skipped => "\u203D".blue
}
#
def initialize(runtime, path_or_io, options) def initialize(runtime, path_or_io, options)
@runtime, @io, @options = runtime, ensure_io(path_or_io), options @runtime = runtime
@exceptions = [] @snippets_input = []
@indent = 0 @io = ensure_io(path_or_io)
@prefixes = options[:prefixes] || {} @prefixes = options[:prefixes] || {}
@delayed_messages = [] @delayed_messages = []
@snippets_input = [] @options = options
@exceptions = []
@indent = 0
end end
#
def before_features(features) def before_features(features)
print_profile_information print_profile_information
end end
#
def after_features(features) def after_features(features)
@io.puts @io.puts
print_summary(features) print_summary(features)
end end
#
def before_feature(feature) def before_feature(feature)
@exceptions = [] @exceptions = []
@indent = 0 @indent = 0
end end
def comment_line(comment_line) #
end
def after_tags(tags) def tag_name(tag_name); end
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) def before_feature_element(feature_element)
@indent = 2 @indent = 2
@scenario_indent = 2 @scenario_indent = 2
end end
def after_feature_element(feature_element) #
end
def before_background(background) def before_background(background)
@indent = 2
@scenario_indent = 2 @scenario_indent = 2
@in_background = true @in_background = true
@indent = 2
end end
#
def after_background(background) def after_background(background)
@in_background = nil @in_background = nil
end 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 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 end
#
def before_step(step) def before_step(step)
@current_step = step @current_step = step
end 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 @hide_this_step = false
if exception if exception
if @exceptions.include?(exception) if @exceptions.include?(exception)
@hide_this_step = true @hide_this_step = true
return return
end end
@exceptions << exception @exceptions << exception
end end
if status != :failed && @in_background ^ background if status != :failed && @in_background ^ background
@hide_this_step = true @hide_this_step = true
return return
end end
@status = status @status = status
end 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) def step_name(keyword, step_match, status, source_indent, background, file_colon_line)
@io.print CHARS[status] @io.print CHARS[status]
@io.print " "
end end
#
def exception(exception, status) def exception(exception, status)
return if @hide_this_step return if @hide_this_step
@io.puts @io.puts
print_exception(exception, status, @indent) print_exception(exception, status, @indent)
@io.flush @io.flush
end end
#
def after_test_step(test_step, result) def after_test_step(test_step, result)
collect_snippet_data(test_step, result) collect_snippet_data(
test_step, result
)
end end
private #
def print_feature_element_name(keyword, name, file_colon_line, source_indent) private
def print_feature_element_name(keyword, name, source_line, indent)
@io.puts @io.puts
names = name.empty? ? [name] : name.split("\n")
line = " #{keyword}: #{names[0]}" names = name.empty? ? [name] : name.each_line.to_a
if @options[:source] line = " #{keyword}: #{names[0]}"
line_comment = "#{file_colon_line}"
@io.print(line_comment) @io.print(source_line) if @options[:source]
end
@io.print(line) @io.print(line)
@io.print " " @io.print " "
@io.flush @io.flush
end end
#
def cell_prefix(status) def cell_prefix(status)
@prefixes[status] @prefixes[status]
end end
#
def print_summary(features) def print_summary(features)
@io.puts @io.puts
print_stats(features, @options) print_stats(features, @options)

View File

@ -1,11 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if ruby --version | grep -q "jruby" time ruby -S bundle exec cucumber \
then -f Jekyll::Cucumber::Formatter "$@"
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