changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/lib/spec/runner/formatter/story/html_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 'erb'
2require 'spec/runner/formatter/base_text_formatter'
3
4module 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">
30EOF
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>
48EOF
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>
59EOF
60 end
61
62 def story_ended(title, narrative)
63 @output.puts <<-EOF
64 </dd>
65 </dl>
66EOF
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">
75EOF
76 end
77
78 def scenario_ended
79 @output.puts <<-EOF
80 </ul>
81 </dd>
82 </dl>
83EOF
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_upcoming(type, description, *args)
102 end
103
104 def step_succeeded(type, description, *args)
105 print_step('passed', type, description, *args) # TODO: uses succeeded CSS class
106 end
107
108 def step_pending(type, description, *args)
109 print_step('pending', type, description, *args)
110 end
111
112 def step_failed(type, description, *args)
113 print_step('failed', type, description, *args)
114 end
115
116 def print_step(klass, type, description, *args)
117 spans = args.map { |arg| "<span class=\"param\">#{arg}</span>" }
118 desc_string = description.step_name
119 arg_regexp = description.arg_regexp
120 i = -1
121 inner = type.to_s.capitalize + ' ' + desc_string.gsub(arg_regexp) { |param| spans[i+=1] }
122 @output.puts " <li class=\"#{klass}\">#{inner}</li>"
123 end
124 end
125 end
126 end
127 end
128end