1 require 'spec/runner/formatter/base_text_formatter'
7 class PlainTextFormatter < BaseTextFormatter
8 def initialize(options, where)
10 @successful_scenario_count = 0
11 @pending_scenario_count = 0
12 @failed_scenarios = []
17 def run_started(count)
19 @output.puts "Running #@count scenarios\n\n"
22 def story_started(title, narrative)
23 @current_story_title = title
24 @output.puts "Story: #{title}\n\n"
25 narrative.each_line do |line|
31 def story_ended(title, narrative)
36 def scenario_started(story_title, scenario_name)
37 @current_scenario_name = scenario_name
38 @scenario_already_failed = false
39 @output.print "\n\n Scenario: #{scenario_name}"
43 def scenario_succeeded(story_title, scenario_name)
44 @successful_scenario_count += 1
47 def scenario_failed(story_title, scenario_name, err)
48 @options.backtrace_tweaker.tweak_backtrace(err)
49 @failed_scenarios << [story_title, scenario_name, err] unless @scenario_already_failed
50 @scenario_already_failed = true
53 def scenario_pending(story_title, scenario_name, msg)
54 @pending_scenario_count += 1 unless @scenario_already_failed
55 @scenario_already_failed = true
59 @output.puts "#@count scenarios: #@successful_scenario_count succeeded, #{@failed_scenarios.size} failed, #@pending_scenario_count pending"
60 unless @pending_steps.empty?
61 @output.puts "\nPending Steps:"
62 @pending_steps.each_with_index do |pending, i|
63 story_name, scenario_name, msg = pending
64 @output.puts "#{i+1}) #{story_name} (#{scenario_name}): #{msg}"
67 unless @failed_scenarios.empty?
68 @output.print "\nFAILURES:"
69 @failed_scenarios.each_with_index do |failure, i|
70 title, scenario_name, err = failure
72 #{i+1}) #{title} (#{scenario_name}) FAILED
73 #{err.class}: #{err.message}
74 #{err.backtrace.join("\n")}
80 def step_succeeded(type, description, *args)
81 found_step(type, description, false, *args)
84 def step_pending(type, description, *args)
85 found_step(type, description, false, *args)
86 @pending_steps << [@current_story_title, @current_scenario_name, description]
87 @output.print " (PENDING)"
91 def step_failed(type, description, *args)
92 found_step(type, description, true, *args)
93 @output.print red(@scenario_ok ? " (FAILED)" : " (SKIPPED)")
97 def collected_steps(steps)
100 def method_missing(sym, *args, &block) #:nodoc:
101 # noop - ignore unknown messages
106 def found_step(type, description, failed, *args)
107 desc_string = description.step_name
108 arg_regexp = description.arg_regexp
109 text = if(type == @previous_type)
112 "\n\n #{type.to_s.capitalize} "
115 text << desc_string.gsub(arg_regexp) { |param| args[i+=1] }
116 @output.print(failed ? red(text) : green(text))
118 if type == :'given scenario'
119 @previous_type = :given
121 @previous_type = type