Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec / lib / spec / runner / formatter / story / plain_text_formatter.rb
blobc3c0c436b3c40b4fdac76032535bd0b2100751f9
1 module Spec
2   module Runner
3     module Formatter
4       module Story
5         class PlainTextFormatter < BaseTextFormatter
6           def initialize(options, where)
7             super
8             @successful_scenario_count = 0
9             @pending_scenario_count = 0
10             @failed_scenarios = []
11             @pending_steps = []
12             @previous_type = nil
13           end
14         
15           def run_started(count)
16             @count = count
17             @output.puts "Running #@count scenarios:\n"
18           end
20           def story_started(title, narrative)
21             @output.puts "Story: #{title}\n\n"
22             narrative.each_line do |line|
23               @output.print "  "
24               @output.print line
25             end
26           end
27         
28           def story_ended(title, narrative)
29             @output.puts
30             @output.puts
31           end
33           def scenario_started(story_title, scenario_name)
34             @scenario_already_failed = false
35             @output.print "\n\nScenario: #{scenario_name}"
36             @scenario_ok = true
37           end
38         
39           def scenario_succeeded(story_title, scenario_name)
40             @successful_scenario_count += 1
41           end
42         
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
46           end
47         
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
52           end
53         
54           def run_ended
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}"
61               end
62             end
63             unless @failed_scenarios.empty?
64               @output.print "\nFAILURES:"
65               @failed_scenarios.each_with_index do |failure, i|
66                 title, scenario_name, err = failure
67                 @output.print %[
68     #{i+1}) #{title} (#{scenario_name}) FAILED
69     #{err.class}: #{err.message}
70     #{err.backtrace.join("\n")}
71     ]
72               end
73             end
74           end
75         
76           def step_succeeded(type, description, *args)
77             found_step(type, description, false, *args)
78           end
79         
80           def step_pending(type, description, *args)
81             found_step(type, description, false, *args)
82             @output.print " (PENDING)"
83             @scenario_ok = false
84           end
85         
86           def step_failed(type, description, *args)
87             found_step(type, description, true, *args)
88             @output.print red(@scenario_ok ? " (FAILED)" : " (SKIPPED)")
89             @scenario_ok = false
90           end
91           
92           def collected_steps(steps)
93           end
95         private
97           def found_step(type, description, failed, *args)
98             text = if(type == @previous_type)
99               "\n  And "
100             else
101               "\n\n  #{type.to_s.capitalize} "
102             end
103             i = -1
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
109             else
110               @previous_type = type
111             end
112           end
113         end
114       end
115     end
116   end