Permalink
Browse files

Cucumber failed steps summary with backtraces

  • Loading branch information...
1 parent 5afa5f1 commit 76a6b4d3efa1cd20f0c8188e38d7904704d0959c @shayarnett shayarnett committed Apr 21, 2010
Showing with 37 additions and 4 deletions.
  1. +30 −1 lib/specjour/cucumber/distributed_formatter.rb
  2. +7 −3 lib/specjour/cucumber/final_report.rb
@@ -10,6 +10,7 @@ def initialize(step_mother, io, options)
@io = io
@options = options
@failing_scenarios = []
+ @step_summary = []
end
def after_features(features)
@@ -31,8 +32,36 @@ def prepare_failures
end
end
+ def prepare_elements(elements, status, kind)
+ output = ''
+ if elements.any?
+ output += format_string("\n(::) #{status} #{kind} (::)\n", status)
+ output += "\n"
+ end
+
+ elements.each_with_index do |element, i|
+ if status == :failed
+ output += print_exception(element.exception, status, 0)
+ else
+ output += format_string(element.backtrace_line, status)
+ output += "\n"
+ end
+ @step_summary << output unless output.blank?
+ end
+ end
+
+ def prepare_steps(type)
+ prepare_elements(step_mother.scenarios(type), type, 'steps')
+ end
+
+ def print_exception(e, status, indent)
+ format_string("#{e.message} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status)
+ end
+
def print_summary
prepare_failures
+ prepare_steps(:failed)
+ prepare_steps(:undefined)
@io.send_message(:worker_summary=, to_hash)
end
@@ -47,7 +76,7 @@ def to_hash
hash[type][outcome] = step_mother.send(type, outcome).size
end
end
- hash.merge!(:failing_scenarios => @failing_scenarios)
+ hash.merge!(:failing_scenarios => @failing_scenarios, :step_summary => @step_summary)
hash
end
@@ -1,10 +1,11 @@
module Specjour
module Cucumber
class Summarizer
- attr_reader :duration, :failing_scenarios
+ attr_reader :duration, :failing_scenarios, :step_summary
def initialize
@duration = 0.0
@failing_scenarios = []
+ @step_summary = []
@scenarios = Hash.new(0)
@steps = Hash.new(0)
end
@@ -18,6 +19,8 @@ def add(stats)
stats.each do |category, hash|
if category == :failing_scenarios
@failing_scenarios += hash
+ elsif category == :step_summary
+ @step_summary += hash
elsif category == :duration
@duration = hash.to_f if duration < hash.to_f
else
@@ -54,8 +57,9 @@ def add(stats)
def summarize
if @summarizer.failing_scenarios.any?
- puts
- puts
+ puts "\n\n"
+ @summarizer.step_summary.each {|f| puts f }
+ puts "\n\n"
puts format_string("Failing Scenarios:", :failed)
@summarizer.failing_scenarios.each {|f| puts f }
end

0 comments on commit 76a6b4d

Please sign in to comment.