imedo (owner)

Revisions

gist: 217658 Download_button fork
public
Description:
Output formatter for cucumber
Public Clone URL: git://gist.github.com/217658.git
Embed All Files: show embed
imedo_ci_formatter.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class ImedoCiFormatter < Cucumber::Ast::Visitor
 
  def initialize(step_mother, io, options)
    super(step_mother)
    @io = io
    @options = options
    @errors = []
    @passed_scenarios = []
    @failed_scenarios = []
    @pending_scenarios = []
    @current_feature_name = ""
    @current_scenario_name = ""
    @empty_scenario = false
  end
 
  def visit_features(features)
    super
    print_summary
  end
 
  def visit_feature_name(name)
    s = name.split("\n").first.gsub(/^(Feature|Story):[ ]*/, '')
    @current_feature_name = s
    @io.print "\n#{@current_feature_name}\t"
  end
 
  def visit_feature_element(feature_element)
    super
    if feature_element.status == :failed
      @failed_scenarios << "#{@current_feature_name}: #{@current_scenario_name}"
      @errors << feature_element.exception
      @io.print "F"
    elsif feature_element.status == :passed and not @empty_scenario
      @passed_scenarios << "#{@current_feature_name}: #{@current_scenario_name}"
      @io.print "."
    else
      @pending_scenarios <<"#{@current_feature_name}: #{@current_scenario_name}"
      @io.print "P"
    end
  end
 
  def visit_scenario_name(keyword, name, file_colon_line, source_indent)
    visit_feature_element_name(keyword, name, file_colon_line, source_indent)
  end
 
  def visit_feature_element_name(keyword, name, file_colon_line, source_indent)
    @current_scenario_name = name
  end
 
  def visit_steps(steps)
    super
    @empty_scenario = steps.empty?
  end
 
  def print_summary
    @io.puts
    @io.puts "\nPending Scenarios:\n\n" if @pending_scenarios.any?
    @pending_scenarios.uniq.each_with_index do |scenario_string, n|
      @io.puts "#{n+1}) #{scenario_string}"
    end
    @io.puts "\nFailed:" if @errors.any?
    @errors.each_with_index do |error,n|
      @io.puts
      @io.puts "#{n+1}) #{error.message}"
      @io.puts error.backtrace.join("\n")
    end
    @io.puts
    if @passed_scenarios.any?
      @io.puts "#{@passed_scenarios.length} scenarios passed"
    end
    if @failed_scenarios.any?
      @io.puts "#{@failed_scenarios.length} scenarios failed"
    end
    if @pending_scenarios.any?
      @io.puts "#{@pending_scenarios.length} scenarios pending"
    end
  end
end