Class: Spec::Runner::Formatter::Story::HtmlFormatter
- Inherits:
-
BaseTextFormatter
- Object
- BaseTextFormatter
- Spec::Runner::Formatter::Story::HtmlFormatter
- Includes:
- ERB::Util
- Defined in:
- lib/spec/runner/formatter/story/html_formatter.rb
Instance Method Summary collapse
- #collected_steps(steps) ⇒ Object
- #found_scenario(type, description) ⇒ Object
-
#initialize(options, where) ⇒ HtmlFormatter
constructor
A new instance of HtmlFormatter.
- #print_step(klass, type, description, *args) ⇒ Object
- #run_ended ⇒ Object
- #run_started(count) ⇒ Object
- #scenario_ended ⇒ Object
- #scenario_failed(story_title, scenario_name, err) ⇒ Object
- #scenario_pending(story_title, scenario_name, reason) ⇒ Object
- #scenario_started(story_title, scenario_name) ⇒ Object
- #scenario_succeeded(story_title, scenario_name) ⇒ Object
- #step_failed(type, description, *args) ⇒ Object
- #step_pending(type, description, *args) ⇒ Object
- #step_succeeded(type, description, *args) ⇒ Object
- #step_upcoming(type, description, *args) ⇒ Object
- #story_ended(title, narrative) ⇒ Object
- #story_started(title, narrative) ⇒ Object
Constructor Details
#initialize(options, where) ⇒ HtmlFormatter
Returns a new instance of HtmlFormatter.
11 12 13 14 15 16 17 18 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 11 def initialize(, where) super @previous_type = nil @scenario_text = "" @story_text = "" @scenario_failed = false @story_failed = false end |
Instance Method Details
#collected_steps(steps) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 42 def collected_steps(steps) unless steps.empty? @output.puts " <ul id=\"stock_steps\" style=\"display: none;\">" steps.each do |step| @output.puts " <li>#{step}</li>" end @output.puts " </ul>" end end |
#found_scenario(type, description) ⇒ Object
117 118 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 117 def found_scenario(type, description) end |
#print_step(klass, type, description, *args) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 149 def print_step(klass, type, description, *args) spans = args.map { |arg| "<span class=\"param\">#{arg}</span>" } desc_string = description.step_name arg_regexp = description.arg_regexp inner = if(type == @previous_type) "And " else "#{type.to_s.capitalize} " end i = -1 inner += desc_string.gsub(arg_regexp) { |param| spans[i+=1] } @scenario_text += " <li class=\"#{klass}\">#{inner}</li>\n" if type == :'given scenario' @previous_type = :given else @previous_type = type end end |
#run_ended ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 52 def run_ended @output.puts <<-EOF </div> </body> </head> EOF end |
#run_started(count) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 20 def run_started(count) @output.puts <<-EOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Stories</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Expires" content="-1" /> <meta http-equiv="Pragma" content="no-cache" /> <script src="javascripts/prototype.js" type="text/javascript"></script> <script src="javascripts/scriptaculous.js" type="text/javascript"></script> <script src="javascripts/rspec.js" type="text/javascript"></script> <link href="stylesheets/rspec.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> EOF end |
#scenario_ended ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 98 def scenario_ended if @scenario_failed @story_text += <<-EOF <dl class="failed"> EOF else @story_text += <<-EOF <dl class="passed"> EOF end @story_text += <<-EOF #{@scenario_text} </ul> </dd> </dl> EOF end |
#scenario_failed(story_title, scenario_name, err) ⇒ Object
128 129 130 131 132 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 128 def scenario_failed(story_title, scenario_name, err) @scenario_failed = true @story_failed = true scenario_ended end |
#scenario_pending(story_title, scenario_name, reason) ⇒ Object
124 125 126 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 124 def scenario_pending(story_title, scenario_name, reason) scenario_ended end |
#scenario_started(story_title, scenario_name) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 88 def scenario_started(story_title, scenario_name) @previous_type = nil @scenario_failed = false @scenario_text = <<-EOF <dt>Scenario: #{h scenario_name}</dt> <dd> <ul class="steps"> EOF end |
#scenario_succeeded(story_title, scenario_name) ⇒ Object
120 121 122 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 120 def scenario_succeeded(story_title, scenario_name) scenario_ended end |
#step_failed(type, description, *args) ⇒ Object
145 146 147 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 145 def step_failed(type, description, *args) print_step('failed', type, description, *args) end |
#step_pending(type, description, *args) ⇒ Object
141 142 143 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 141 def step_pending(type, description, *args) print_step('pending', type, description, *args) end |
#step_succeeded(type, description, *args) ⇒ Object
137 138 139 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 137 def step_succeeded(type, description, *args) print_step('passed', type, description, *args) # TODO: uses succeeded CSS class end |
#step_upcoming(type, description, *args) ⇒ Object
134 135 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 134 def step_upcoming(type, description, *args) end |
#story_ended(title, narrative) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 71 def story_ended(title, narrative) if @story_failed @output.puts <<-EOF <dl class="story failed"> EOF else @output.puts <<-EOF <dl class="story passed"> EOF end @output.puts <<-EOF #{@story_text} </dd> </dl> EOF end |
#story_started(title, narrative) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/spec/runner/formatter/story/html_formatter.rb', line 60 def story_started(title, narrative) @story_failed = false @story_text = <<-EOF <dt>Story: #{h title}</dt> <dd> <p> #{h(narrative).split("\n").join("<br />")} </p> EOF end |