public
Description: Behaviour Driven Development framework for Ruby
Homepage: http://rspec.info
Clone URL: git://github.com/dchelimsky/rspec.git
Click here to lend your support to: rspec and make a donation at www.pledgie.com !
story progress bar formatter and more colourful summaries from the plain text 
story formatter
Joseph Wilk (author)
Thu Jul 24 04:21:12 -0700 2008
dchelimsky (committer)
Tue Aug 05 02:17:56 -0700 2008
commit  59128a36e46becf3045ffe6ab4a32bb10f0ab8e9
tree    3bd4b3830123c60db5dc04db4100f60382dbb47b
parent  5fd78361039d069449f91dc506ae2bf3d9d616de
...
104
105
106
107
 
 
 
 
 
 
 
 
108
109
110
...
116
117
118
119
120
121
122
123
 
 
 
 
124
125
126
...
104
105
106
 
107
108
109
110
111
112
113
114
115
116
117
...
123
124
125
 
 
 
 
 
126
127
128
129
130
131
132
0
@@ -104,7 +104,14 @@ module Spec
0
           end
0
           
0
           def run_ended
0
-            @output.puts "#@count scenarios: #@successful_scenario_count succeeded, #{@failed_scenarios.size} failed, #@pending_scenario_count pending"
0
+            summary_text = "#@count scenarios: #@successful_scenario_count succeeded, #{@failed_scenarios.size} failed, #@pending_scenario_count pending"
0
+            if !@failed_scenarios.empty?
0
+              @output.puts red(summary_text)
0
+            elsif !@pending_steps.empty?
0
+              @output.puts yellow(summary_text)
0
+            else
0
+              @output.puts green(summary_text)
0
+            end
0
             unless @pending_steps.empty?
0
               @output.puts "\nPending Steps:"
0
               @pending_steps.each_with_index do |pending, i|
0
@@ -116,11 +123,10 @@ module Spec
0
               @output.print "\nFAILURES:"
0
               @failed_scenarios.each_with_index do |failure, i|
0
                 title, scenario_name, err = failure
0
-                @output.print %[
0
-    #{i+1}) #{title} (#{scenario_name}) FAILED
0
-    #{err.class}: #{err.message}
0
-    #{err.backtrace.join("\n")}
0
-]
0
+                @output.print "\n    #{i+1}) "
0
+                @output.print red("#{title} (#{scenario_name}) FAILED")
0
+                @output.print red("\n    #{err.class}: #{err.message}")
0
+                @output.print "\n    #{err.backtrace.join("\n")}\n"
0
               end
0
             end            
0
           end
...
54
55
56
 
57
58
59
...
54
55
56
57
58
59
60
0
@@ -54,6 +54,7 @@ module Spec
0
                                                     "Builtin formats for stories: ",
0
                                                     "plain|p              : Plain Text",
0
                                                     "html|h               : A nice HTML report",
0
+                                                    "progress|r           : Text progress",
0
                                                     " ",
0
                                                     "FORMAT can also be the name of a custom formatter class",
0
                                                     "(in which case you should also specify --require to load it)"],
...
24
25
26
27
28
29
30
 
 
 
 
 
 
 
31
32
33
...
24
25
26
 
 
 
 
27
28
29
30
31
32
33
34
35
36
0
@@ -24,10 +24,13 @@ module Spec
0
       }
0
 
0
       STORY_FORMATTERS = {
0
-        'plain' => ['spec/runner/formatter/story/plain_text_formatter', 'Formatter::Story::PlainTextFormatter'],
0
-            'p' => ['spec/runner/formatter/story/plain_text_formatter', 'Formatter::Story::PlainTextFormatter'],
0
-         'html' => ['spec/runner/formatter/story/html_formatter',       'Formatter::Story::HtmlFormatter'],
0
-            'h' => ['spec/runner/formatter/story/html_formatter',       'Formatter::Story::HtmlFormatter']
0
+        'plain' => ['spec/runner/formatter/story/plain_text_formatter',   'Formatter::Story::PlainTextFormatter'],
0
+            'p' => ['spec/runner/formatter/story/plain_text_formatter',   'Formatter::Story::PlainTextFormatter'],
0
+         'html' => ['spec/runner/formatter/story/html_formatter',         'Formatter::Story::HtmlFormatter'],
0
+            'h' => ['spec/runner/formatter/story/html_formatter',         'Formatter::Story::HtmlFormatter'],
0
+     'progress' => ['spec/runner/formatter/story/progress_bar_formatter', 'Formatter::Story::ProgressBarFormatter'],
0
+            'r' => ['spec/runner/formatter/story/progress_bar_formatter', 'Formatter::Story::ProgressBarFormatter']
0
+            
0
       }
0
 
0
       attr_accessor(
...
159
160
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
163
164
...
180
181
182
 
 
 
 
 
 
 
 
 
 
 
 
 
183
184
185
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
0
@@ -159,6 +159,45 @@ module Spec
0
             @out.string.should include("3 scenarios: 1 succeeded, 1 failed, 1 pending")
0
           end
0
 
0
+          it 'should show test summary in red if there were failed scenarios' do
0
+            # when
0
+            @out.stub!(:tty?).and_return(true)
0
+            @options.stub!(:colour).and_return(true)
0
+
0
+            @formatter.scenario_started(nil, nil)
0
+            @formatter.scenario_failed('story', 'scenario', exception_from { raise RuntimeError, 'oops' })
0
+            @formatter.run_ended
0
+
0
+            # then
0
+            @out.string.should include("\e[31m scenarios: 0 succeeded, 1 failed, 0 pending\e[0m")
0
+          end
0
+
0
+          it 'should show test summary in yellow if there are pending scenarios' do
0
+            # when
0
+            @out.stub!(:tty?).and_return(true)
0
+            @options.stub!(:colour).and_return(true)
0
+
0
+            @formatter.scenario_started(nil, nil)
0
+            @formatter.scenario_pending('story', 'scenario', '')
0
+            @formatter.run_ended
0
+
0
+            # then
0
+            @out.string.should include("\e[32m scenarios: 0 succeeded, 0 failed, 1 pending\e[0m")
0
+          end
0
+
0
+          it 'should show test summary in green if all scenarios pass' do
0
+            # when
0
+            @out.stub!(:tty?).and_return(true)
0
+            @options.stub!(:colour).and_return(true)
0
+
0
+            @formatter.scenario_started(nil, nil)
0
+            @formatter.scenario_succeeded('story', 'scenario')
0
+            @formatter.run_ended
0
+
0
+            # then
0
+            @out.string.should include("\e[32m scenarios: 1 succeeded, 0 failed, 0 pending\e[0m")
0
+          end
0
+        
0
           it 'should produce details of the first failure each failed scenario when the run ends' do
0
             # when
0
             @formatter.run_started(3)
0
@@ -180,6 +219,19 @@ module Spec
0
             @out.string.should include("RuntimeError: oops3")
0
           end
0
 
0
+          it 'should produce details of the failures in red when the run ends' do
0
+            # when
0
+            @out.stub!(:tty?).and_return(true)
0
+            @options.stub!(:colour).and_return(true)
0
+            @formatter.scenario_started(nil, nil)
0
+            @formatter.scenario_failed('story', 'scenario1', exception_from { raise RuntimeError, 'oops1' })
0
+            @formatter.run_ended
0
+
0
+            # then
0
+            @out.string.should =~ /\e\[31m[\n\s]*story \(scenario1\) FAILED\e\[0m/m
0
+            @out.string.should =~ /\e\[31m[\n\s]*RuntimeError: oops1\e\[0m/m
0
+          end
0
+
0
           it 'should produce details of each pending step when the run ends' do
0
             # when
0
             @formatter.run_started(2)

Comments