changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require 'spec/runner/formatter/base_text_formatter'
2
3module Spec
4 module Runner
5 module Formatter
6 module Story
7 class PlainTextFormatter < BaseTextFormatter
8 def initialize(options, where)
9 super
10 @successful_scenario_count = 0
11 @pending_scenario_count = 0
12 @failed_scenarios = []
13 @pending_steps = []
14 @previous_type = nil
15 end
16
17 def run_started(count)
18 @count = count
19 @output.puts "Running #@count scenarios\n\n"
20 end
21
22 def story_started(title, narrative)
23 @current_story_title = title
24 @output.puts "Story: #{title}\n\n"
25 narrative.each_line do |line|
26 @output.print " "
27 @output.print line
28 end
29 end
30
31 def story_ended(title, narrative)
32 @output.puts
33 @output.puts
34 end
35
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}"
40 @scenario_ok = true
41 end
42
43 def scenario_succeeded(story_title, scenario_name)
44 @successful_scenario_count += 1
45 end
46
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
51 end
52
53 def scenario_pending(story_title, scenario_name, msg)
54 @pending_scenario_count += 1 unless @scenario_already_failed
55 @scenario_already_failed = true
56 end
57
58 def run_ended
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}"
65 end
66 end
67 unless @failed_scenarios.empty?
68 @output.print "\nFAILURES:"
69 @failed_scenarios.each_with_index do |failure, i|
70 title, scenario_name, err = failure
71 @output.print %[
72 #{i+1}) #{title} (#{scenario_name}) FAILED
73 #{err.class}: #{err.message}
74 #{err.backtrace.join("\n")}
75]
76 end
77 end
78 end
79
80 def step_upcoming(type, description, *args)
81 end
82
83 def step_succeeded(type, description, *args)
84 found_step(type, description, false, *args)
85 end
86
87 def step_pending(type, description, *args)
88 found_step(type, description, false, *args)
89 @pending_steps << [@current_story_title, @current_scenario_name, description]
90 @output.print " (PENDING)"
91 @scenario_ok = false
92 end
93
94 def step_failed(type, description, *args)
95 found_step(type, description, true, *args)
96 @output.print red(@scenario_ok ? " (FAILED)" : " (SKIPPED)")
97 @scenario_ok = false
98 end
99
100 def collected_steps(steps)
101 end
102
103 def method_missing(sym, *args, &block) #:nodoc:
104 # noop - ignore unknown messages
105 end
106
107 private
108
109 def found_step(type, description, failed, *args)
110 desc_string = description.step_name
111 arg_regexp = description.arg_regexp
112 text = if(type == @previous_type)
113 "\n And "
114 else
115 "\n\n #{type.to_s.capitalize} "
116 end
117 i = -1
118 text << desc_string.gsub(arg_regexp) { |param| args[i+=1] }
119 @output.print(failed ? red(text) : green(text))
120
121 if type == :'given scenario'
122 @previous_type = :given
123 else
124 @previous_type = type
125 end
126 end
127 end
128 end
129 end
130 end
131end