Class: Spec::Runner::Formatter::Story::HtmlFormatter

Inherits:
BaseTextFormatter show all
Includes:
ERB::Util
Defined in:
lib/gems/rspec-1.1.11/lib/spec/runner/formatter/story/html_formatter.rb

Instance Attribute Summary

Attributes inherited from BaseTextFormatter

#output, #pending_examples

Attributes inherited from BaseFormatter

#example_group, #options, #where

Instance Method Summary collapse

Methods inherited from BaseTextFormatter

#close, #colourise, #dump_failure, #dump_pending, #dump_summary, #example_pending, #format_backtrace

Methods inherited from BaseFormatter

#add_example_group, #close, #dump_failure, #dump_pending, #dump_summary, #example_failed, #example_passed, #example_pending, #example_started, #start, #start_dump

Constructor Details

#initialize(options, where) ⇒ HtmlFormatter

Returns a new instance of HtmlFormatter.



11
12
13
14
15
16
17
18
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/story/html_formatter.rb', line 11

def initialize(options, 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/gems/rspec-1.1.11/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/gems/rspec-1.1.11/lib/spec/runner/formatter/story/html_formatter.rb', line 117

def found_scenario(type, description)
end


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/gems/rspec-1.1.11/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_endedObject



52
53
54
55
56
57
58
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/story/html_formatter.rb', line 52

def run_ended
  @output.puts "    </div>\n  </body>\n</head>\n"
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/gems/rspec-1.1.11/lib/spec/runner/formatter/story/html_formatter.rb', line 20

def run_started(count)
  @output.puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html \n  PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n  <head>\n    <title>Stories</title>\n    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n    <meta http-equiv=\"Expires\" content=\"-1\" />\n    <meta http-equiv=\"Pragma\" content=\"no-cache\" />\n    <script src=\"javascripts/prototype.js\" type=\"text/javascript\"></script>\n    <script src=\"javascripts/scriptaculous.js\" type=\"text/javascript\"></script>\n    <script src=\"javascripts/rspec.js\" type=\"text/javascript\"></script>\n    <link href=\"stylesheets/rspec.css\" rel=\"stylesheet\" type=\"text/css\" />\n  </head>\n  <body>\n    <div id=\"container\">\n"
end

#scenario_endedObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/story/html_formatter.rb', line 98

def scenario_ended
  if @scenario_failed
    @story_text += "  <dl class=\"failed\">\n"
  else
    @story_text += "  <dl class=\"passed\">\n"
  end
  
  @story_text += "\#{@scenario_text}\n      </ul>\n    </dd>\n  </dl>\n"
end

#scenario_failed(story_title, scenario_name, err) ⇒ Object



128
129
130
131
132
# File 'lib/gems/rspec-1.1.11/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/gems/rspec-1.1.11/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/gems/rspec-1.1.11/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 = "    <dt>Scenario: \#{h scenario_name}</dt>\n    <dd>\n      <ul class=\"steps\">\n"
end

#scenario_succeeded(story_title, scenario_name) ⇒ Object



120
121
122
# File 'lib/gems/rspec-1.1.11/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/gems/rspec-1.1.11/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/gems/rspec-1.1.11/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/gems/rspec-1.1.11/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/gems/rspec-1.1.11/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/gems/rspec-1.1.11/lib/spec/runner/formatter/story/html_formatter.rb', line 71

def story_ended(title, narrative)     
  if @story_failed
    @output.puts "      <dl class=\"story failed\">\n"
  else
    @output.puts "      <dl class=\"story passed\">\n"
  end
    @output.puts "\#{@story_text}\n        </dd>\n      </dl>\n"
end

#story_started(title, narrative) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/gems/rspec-1.1.11/lib/spec/runner/formatter/story/html_formatter.rb', line 60

def story_started(title, narrative)
  @story_failed = false
  @story_text = "        <dt>Story: \#{h title}</dt>\n        <dd>\n<p>\n  \#{h(narrative).split(\"\\n\").join(\"<br />\")}\n</p>\n" 
end