5 class PlainTextFormatter < BaseTextFormatter
6 def initialize(options, where)
8 @successful_scenario_count = 0
9 @pending_scenario_count = 0
10 @failed_scenarios = []
15 def run_started(count)
17 @output.puts "Running #@count scenarios:\n"
20 def story_started(title, narrative)
21 @output.puts "Story: #{title}\n\n"
22 narrative.each_line do |line|
28 def story_ended(title, narrative)
33 def scenario_started(story_title, scenario_name)
34 @scenario_already_failed = false
35 @output.print "\n\nScenario: #{scenario_name}"
39 def scenario_succeeded(story_title, scenario_name)
40 @successful_scenario_count += 1
43 def scenario_failed(story_title, scenario_name, err)
44 @failed_scenarios << [story_title, scenario_name, err] unless @scenario_already_failed
45 @scenario_already_failed = true
48 def scenario_pending(story_title, scenario_name, msg)
49 @pending_steps << [story_title, scenario_name, msg]
50 @pending_scenario_count += 1 unless @scenario_already_failed
51 @scenario_already_failed = true
55 @output.puts "\n\n#@count scenarios: #@successful_scenario_count succeeded, #{@failed_scenarios.size} failed, #@pending_scenario_count pending"
56 unless @pending_steps.empty?
57 @output.puts "\nPending Steps:"
58 @pending_steps.each_with_index do |pending, i|
59 title, scenario_name, msg = pending
60 @output.puts "#{i+1}) #{title} (#{scenario_name}): #{msg}"
63 unless @failed_scenarios.empty?
64 @output.print "\nFAILURES:"
65 @failed_scenarios.each_with_index do |failure, i|
66 title, scenario_name, err = failure
68 #{i+1}) #{title} (#{scenario_name}) FAILED
69 #{err.class}: #{err.message}
70 #{err.backtrace.join("\n")}
76 def step_succeeded(type, description, *args)
77 found_step(type, description, false, *args)
80 def step_pending(type, description, *args)
81 found_step(type, description, false, *args)
82 @output.print " (PENDING)"
86 def step_failed(type, description, *args)
87 found_step(type, description, true, *args)
88 @output.print red(@scenario_ok ? " (FAILED)" : " (SKIPPED)")
92 def collected_steps(steps)
97 def found_step(type, description, failed, *args)
98 text = if(type == @previous_type)
101 "\n\n #{type.to_s.capitalize} "
104 text << description.gsub(::Spec::Story::Step::PARAM_PATTERN) { |param| args[i+=1] }
105 @output.print(failed ? red(text) : green(text))
107 if type == :'given scenario'
108 @previous_type = :given
110 @previous_type = type