1 #!/usr/bin/ruby |
|
2 |
|
3 begin |
|
4 require 'ezmlm' |
|
5 rescue LoadError |
|
6 unless Object.const_defined?( :Gem ) |
|
7 require 'rubygems' |
|
8 retry |
|
9 end |
|
10 raise |
|
11 end |
|
12 |
|
13 module Ezmlm::SpecHelpers |
|
14 |
|
15 ############### |
|
16 module_function |
|
17 ############### |
|
18 |
|
19 ### Create a temporary working directory and return |
|
20 ### a Pathname object for it. |
|
21 ### |
|
22 def make_tempdir |
|
23 dirname = "%s.%d.%0.4f" % [ |
|
24 'ezmlm_spec', |
|
25 Process.pid, |
|
26 (Time.now.to_f % 3600), |
|
27 ] |
|
28 tempdir = Pathname.new( Dir.tmpdir ) + dirname |
|
29 tempdir.mkpath |
|
30 |
|
31 return tempdir |
|
32 end |
|
33 |
|
34 |
|
35 end |
|
36 |
|
37 # Override the badly-formatted output of the RSpec HTML formatter |
|
38 require 'spec/runner/formatter/html_formatter' |
|
39 |
|
40 class Spec::Runner::Formatter::HtmlFormatter |
|
41 def example_failed( example, counter, failure ) |
|
42 failure_style = failure.pending_fixed? ? 'pending_fixed' : 'failed' |
|
43 |
|
44 unless @header_red |
|
45 @output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" |
|
46 @header_red = true |
|
47 end |
|
48 |
|
49 unless @example_group_red |
|
50 css_class = 'example_group_%d' % [current_example_group_number] |
|
51 @output.puts " <script type=\"text/javascript\">makeRed('#{css_class}');</script>" |
|
52 @example_group_red = true |
|
53 end |
|
54 |
|
55 move_progress() |
|
56 |
|
57 @output.puts " <dd class=\"spec #{failure_style}\">", |
|
58 " <span class=\"failed_spec_name\">#{h(example.description)}</span>", |
|
59 " <div class=\"failure\" id=\"failure_#{counter}\">" |
|
60 if failure.exception |
|
61 backtrace = format_backtrace( failure.exception.backtrace ) |
|
62 message = failure.exception.message |
|
63 |
|
64 @output.puts " <div class=\"message\"><code>#{h message}</code></div>", |
|
65 " <div class=\"backtrace\"><pre>#{backtrace}</pre></div>" |
|
66 end |
|
67 |
|
68 if extra = extra_failure_content( failure ) |
|
69 @output.puts( extra ) |
|
70 end |
|
71 |
|
72 @output.puts " </div>", |
|
73 " </dd>" |
|
74 @output.flush |
|
75 end |
|
76 |
|
77 |
|
78 alias_method :default_global_styles, :global_styles |
|
79 |
|
80 def global_styles |
|
81 css = default_global_styles() |
|
82 css << %Q{ |
|
83 /* Stuff added by #{__FILE__} */ |
|
84 |
|
85 /* Overrides */ |
|
86 #rspec-header { |
|
87 -webkit-box-shadow: #333 0 2px 5px; |
|
88 margin-bottom: 1em; |
|
89 } |
|
90 |
|
91 .example_group dt { |
|
92 -webkit-box-shadow: #333 0 2px 3px; |
|
93 } |
|
94 |
|
95 /* Style for log output */ |
|
96 dd.log-message { |
|
97 background: #eee; |
|
98 padding: 0 2em; |
|
99 margin: 0.2em 1em; |
|
100 border-bottom: 1px dotted #999; |
|
101 border-top: 1px dotted #999; |
|
102 text-indent: -1em; |
|
103 } |
|
104 |
|
105 /* Parts of the message */ |
|
106 dd.log-message .log-time { |
|
107 font-weight: bold; |
|
108 } |
|
109 dd.log-message .log-time:after { |
|
110 content: ": "; |
|
111 } |
|
112 dd.log-message .log-level { |
|
113 font-variant: small-caps; |
|
114 border: 1px solid #ccc; |
|
115 padding: 1px 2px; |
|
116 } |
|
117 dd.log-message .log-name { |
|
118 font-size: 1.2em; |
|
119 color: #1e51b2; |
|
120 } |
|
121 dd.log-message .log-name:before { content: "«"; } |
|
122 dd.log-message .log-name:after { content: "»"; } |
|
123 |
|
124 dd.log-message .log-message-text { |
|
125 padding-left: 4px; |
|
126 font-family: Monaco, "Andale Mono", "Vera Sans Mono", mono; |
|
127 } |
|
128 |
|
129 |
|
130 /* Distinguish levels */ |
|
131 dd.log-message.debug { color: #666; } |
|
132 dd.log-message.info {} |
|
133 |
|
134 dd.log-message.warn, |
|
135 dd.log-message.error { |
|
136 background: #ff9; |
|
137 } |
|
138 dd.log-message.error .log-level, |
|
139 dd.log-message.error .log-message-text { |
|
140 color: #900; |
|
141 } |
|
142 dd.log-message.fatal { |
|
143 background: #900; |
|
144 color: white; |
|
145 font-weight: bold; |
|
146 border: 0; |
|
147 } |
|
148 dd.log-message.fatal .log-name { |
|
149 color: white; |
|
150 } |
|
151 } |
|
152 |
|
153 return css |
|
154 end |
|
155 end |
|
156 |
|
157 |
|