]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/runner/formatter/story/html_formatter.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / runner / formatter / story / html_formatter.rb
1 require 'erb'
2 require 'spec/runner/formatter/base_text_formatter'
3
4 module Spec
5   module Runner
6     module Formatter
7       module Story
8         class HtmlFormatter < BaseTextFormatter
9           include ERB::Util
10           
11           def run_started(count)
12             @output.puts <<-EOF
13 <?xml version="1.0" encoding="UTF-8"?>
14 <!DOCTYPE html 
15   PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
16   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
17 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
18   <head>
19     <title>Stories</title>
20     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
21     <meta http-equiv="Expires" content="-1" />
22     <meta http-equiv="Pragma" content="no-cache" />
23     <script src="javascripts/prototype.js" type="text/javascript"></script>
24     <script src="javascripts/scriptaculous.js" type="text/javascript"></script>
25     <script src="javascripts/rspec.js" type="text/javascript"></script>
26     <link href="stylesheets/rspec.css" rel="stylesheet" type="text/css" />
27   </head>
28   <body>
29     <div id="container">
30 EOF
31           end
32
33           def collected_steps(steps)
34             unless steps.empty?
35               @output.puts "      <ul id=\"stock_steps\" style=\"display: none;\">"
36               steps.each do |step|
37                 @output.puts "        <li>#{step}</li>"
38               end
39               @output.puts "      </ul>"
40             end
41           end
42
43           def run_ended
44             @output.puts <<-EOF
45     </div>
46   </body>
47 </head>
48 EOF
49           end
50           
51           def story_started(title, narrative)
52             @output.puts <<-EOF
53       <dl class="story passed">
54         <dt>Story: #{h title}</dt>
55         <dd>
56           <p>
57             #{h(narrative).split("\n").join("<br />")}
58           </p>
59 EOF
60           end
61
62           def story_ended(title, narrative)
63             @output.puts <<-EOF
64         </dd>
65       </dl>
66 EOF
67           end
68
69           def scenario_started(story_title, scenario_name)
70             @output.puts <<-EOF
71           <dl class="passed">
72             <dt>Scenario: #{h scenario_name}</dt>
73             <dd>
74               <ul class="steps">
75 EOF
76           end
77
78           def scenario_ended
79             @output.puts <<-EOF
80               </ul>
81             </dd>
82           </dl>
83 EOF
84           end
85           
86           def found_scenario(type, description)
87           end
88
89           def scenario_succeeded(story_title, scenario_name)
90             scenario_ended
91           end
92
93           def scenario_pending(story_title, scenario_name, reason)
94             scenario_ended
95           end
96
97           def scenario_failed(story_title, scenario_name, err)
98             scenario_ended
99           end
100
101           def step_succeeded(type, description, *args)
102             print_step('passed', type, description, *args) # TODO: uses succeeded CSS class
103           end
104
105           def step_pending(type, description, *args)
106             print_step('pending', type, description, *args)
107           end
108
109           def step_failed(type, description, *args)
110             print_step('failed', type, description, *args)
111           end
112           
113           def print_step(klass, type, description, *args)
114             spans = args.map { |arg| "<span class=\"param\">#{arg}</span>" }
115             desc_string = description.step_name
116             arg_regexp = description.arg_regexp           
117             i = -1
118             inner = type.to_s.capitalize + ' ' + desc_string.gsub(arg_regexp) { |param| spans[i+=1] }
119             @output.puts "                <li class=\"#{klass}\">#{inner}</li>"
120           end
121         end
122       end
123     end
124   end
125 end