rspec-core 2.11.1 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +3 -1
  5. data/Changelog.md +1814 -29
  6. data/{License.txt → LICENSE.md} +6 -4
  7. data/README.md +197 -48
  8. data/exe/rspec +2 -23
  9. data/lib/rspec/autorun.rb +1 -0
  10. data/lib/rspec/core/backtrace_formatter.rb +65 -0
  11. data/lib/rspec/core/bisect/coordinator.rb +62 -0
  12. data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
  13. data/lib/rspec/core/bisect/fork_runner.rb +138 -0
  14. data/lib/rspec/core/bisect/server.rb +61 -0
  15. data/lib/rspec/core/bisect/shell_command.rb +126 -0
  16. data/lib/rspec/core/bisect/shell_runner.rb +73 -0
  17. data/lib/rspec/core/bisect/utilities.rb +69 -0
  18. data/lib/rspec/core/configuration.rb +1846 -407
  19. data/lib/rspec/core/configuration_options.rb +154 -50
  20. data/lib/rspec/core/did_you_mean.rb +46 -0
  21. data/lib/rspec/core/drb.rb +120 -0
  22. data/lib/rspec/core/dsl.rb +90 -18
  23. data/lib/rspec/core/example.rb +488 -152
  24. data/lib/rspec/core/example_group.rb +733 -294
  25. data/lib/rspec/core/example_status_persister.rb +235 -0
  26. data/lib/rspec/core/filter_manager.rb +175 -147
  27. data/lib/rspec/core/flat_map.rb +20 -0
  28. data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
  29. data/lib/rspec/core/formatters/base_formatter.rb +32 -130
  30. data/lib/rspec/core/formatters/base_text_formatter.rb +62 -190
  31. data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
  32. data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
  33. data/lib/rspec/core/formatters/console_codes.rb +76 -0
  34. data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
  35. data/lib/rspec/core/formatters/documentation_formatter.rb +62 -27
  36. data/lib/rspec/core/formatters/exception_presenter.rb +521 -0
  37. data/lib/rspec/core/formatters/failure_list_formatter.rb +23 -0
  38. data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
  39. data/lib/rspec/core/formatters/helpers.rb +93 -14
  40. data/lib/rspec/core/formatters/html_formatter.rb +104 -415
  41. data/lib/rspec/core/formatters/html_printer.rb +414 -0
  42. data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
  43. data/lib/rspec/core/formatters/json_formatter.rb +102 -0
  44. data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
  45. data/lib/rspec/core/formatters/progress_formatter.rb +12 -15
  46. data/lib/rspec/core/formatters/protocol.rb +182 -0
  47. data/lib/rspec/core/formatters/snippet_extractor.rb +115 -39
  48. data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
  49. data/lib/rspec/core/formatters.rb +279 -0
  50. data/lib/rspec/core/hooks.rb +451 -300
  51. data/lib/rspec/core/invocations.rb +87 -0
  52. data/lib/rspec/core/memoized_helpers.rb +580 -0
  53. data/lib/rspec/core/metadata.rb +395 -173
  54. data/lib/rspec/core/metadata_filter.rb +255 -0
  55. data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
  56. data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
  57. data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
  58. data/lib/rspec/core/mocking_adapters/null.rb +14 -0
  59. data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
  60. data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
  61. data/lib/rspec/core/notifications.rb +521 -0
  62. data/lib/rspec/core/option_parser.rb +208 -64
  63. data/lib/rspec/core/ordering.rb +169 -0
  64. data/lib/rspec/core/output_wrapper.rb +29 -0
  65. data/lib/rspec/core/pending.rb +115 -59
  66. data/lib/rspec/core/profiler.rb +34 -0
  67. data/lib/rspec/core/project_initializer/.rspec +1 -0
  68. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +98 -0
  69. data/lib/rspec/core/project_initializer.rb +26 -65
  70. data/lib/rspec/core/rake_task.rb +140 -131
  71. data/lib/rspec/core/reporter.rb +207 -44
  72. data/lib/rspec/core/ruby_project.rb +15 -6
  73. data/lib/rspec/core/runner.rb +180 -44
  74. data/lib/rspec/core/sandbox.rb +37 -0
  75. data/lib/rspec/core/set.rb +54 -0
  76. data/lib/rspec/core/shared_context.rb +25 -19
  77. data/lib/rspec/core/shared_example_group.rb +229 -54
  78. data/lib/rspec/core/shell_escape.rb +49 -0
  79. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  80. data/lib/rspec/core/version.rb +3 -1
  81. data/lib/rspec/core/warnings.rb +40 -0
  82. data/lib/rspec/core/world.rb +208 -49
  83. data/lib/rspec/core.rb +166 -80
  84. data.tar.gz.sig +0 -0
  85. metadata +230 -445
  86. metadata.gz.sig +0 -0
  87. data/exe/autospec +0 -13
  88. data/features/Autotest.md +0 -38
  89. data/features/README.md +0 -17
  90. data/features/Upgrade.md +0 -364
  91. data/features/command_line/README.md +0 -28
  92. data/features/command_line/example_name_option.feature +0 -101
  93. data/features/command_line/exit_status.feature +0 -83
  94. data/features/command_line/format_option.feature +0 -81
  95. data/features/command_line/init.feature +0 -18
  96. data/features/command_line/line_number_appended_to_path.feature +0 -140
  97. data/features/command_line/line_number_option.feature +0 -58
  98. data/features/command_line/order.feature +0 -29
  99. data/features/command_line/pattern_option.feature +0 -31
  100. data/features/command_line/rake_task.feature +0 -68
  101. data/features/command_line/ruby.feature +0 -22
  102. data/features/command_line/tag.feature +0 -91
  103. data/features/configuration/alias_example_to.feature +0 -48
  104. data/features/configuration/custom_settings.feature +0 -84
  105. data/features/configuration/default_path.feature +0 -38
  106. data/features/configuration/fail_fast.feature +0 -77
  107. data/features/configuration/read_options_from_file.feature +0 -87
  108. data/features/example_groups/basic_structure.feature +0 -55
  109. data/features/example_groups/shared_context.feature +0 -74
  110. data/features/example_groups/shared_examples.feature +0 -204
  111. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
  112. data/features/filtering/exclusion_filters.feature +0 -139
  113. data/features/filtering/if_and_unless.feature +0 -168
  114. data/features/filtering/inclusion_filters.feature +0 -105
  115. data/features/filtering/run_all_when_everything_filtered.feature +0 -46
  116. data/features/formatters/custom_formatter.feature +0 -36
  117. data/features/formatters/text_formatter.feature +0 -46
  118. data/features/helper_methods/arbitrary_methods.feature +0 -40
  119. data/features/helper_methods/let.feature +0 -50
  120. data/features/helper_methods/modules.feature +0 -149
  121. data/features/hooks/around_hooks.feature +0 -343
  122. data/features/hooks/before_and_after_hooks.feature +0 -423
  123. data/features/hooks/filtering.feature +0 -234
  124. data/features/metadata/current_example.feature +0 -17
  125. data/features/metadata/described_class.feature +0 -17
  126. data/features/metadata/user_defined.feature +0 -113
  127. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  128. data/features/mock_framework_integration/use_flexmock.feature +0 -96
  129. data/features/mock_framework_integration/use_mocha.feature +0 -97
  130. data/features/mock_framework_integration/use_rr.feature +0 -98
  131. data/features/mock_framework_integration/use_rspec.feature +0 -97
  132. data/features/pending/pending_examples.feature +0 -229
  133. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  134. data/features/step_definitions/additional_cli_steps.rb +0 -30
  135. data/features/subject/attribute_of_subject.feature +0 -124
  136. data/features/subject/explicit_subject.feature +0 -82
  137. data/features/subject/implicit_receiver.feature +0 -29
  138. data/features/subject/implicit_subject.feature +0 -63
  139. data/features/support/env.rb +0 -12
  140. data/lib/autotest/discover.rb +0 -1
  141. data/lib/autotest/rspec2.rb +0 -73
  142. data/lib/rspec/core/backward_compatibility.rb +0 -65
  143. data/lib/rspec/core/command_line.rb +0 -36
  144. data/lib/rspec/core/deprecation.rb +0 -36
  145. data/lib/rspec/core/drb_command_line.rb +0 -26
  146. data/lib/rspec/core/drb_options.rb +0 -87
  147. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  148. data/lib/rspec/core/extensions/kernel.rb +0 -9
  149. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  150. data/lib/rspec/core/extensions/ordered.rb +0 -21
  151. data/lib/rspec/core/extensions.rb +0 -4
  152. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  153. data/lib/rspec/core/let.rb +0 -110
  154. data/lib/rspec/core/load_path.rb +0 -3
  155. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  156. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  157. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  158. data/lib/rspec/core/mocking/with_mocha.rb +0 -29
  159. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  160. data/lib/rspec/core/mocking/with_rspec.rb +0 -23
  161. data/lib/rspec/core/subject.rb +0 -219
  162. data/spec/autotest/discover_spec.rb +0 -19
  163. data/spec/autotest/failed_results_re_spec.rb +0 -45
  164. data/spec/autotest/rspec_spec.rb +0 -123
  165. data/spec/command_line/order_spec.rb +0 -137
  166. data/spec/rspec/core/command_line_spec.rb +0 -108
  167. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  168. data/spec/rspec/core/configuration_options_spec.rb +0 -377
  169. data/spec/rspec/core/configuration_spec.rb +0 -1196
  170. data/spec/rspec/core/deprecations_spec.rb +0 -66
  171. data/spec/rspec/core/drb_command_line_spec.rb +0 -108
  172. data/spec/rspec/core/drb_options_spec.rb +0 -180
  173. data/spec/rspec/core/dsl_spec.rb +0 -17
  174. data/spec/rspec/core/example_group_spec.rb +0 -1098
  175. data/spec/rspec/core/example_spec.rb +0 -370
  176. data/spec/rspec/core/filter_manager_spec.rb +0 -256
  177. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -80
  178. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -363
  179. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -88
  180. data/spec/rspec/core/formatters/helpers_spec.rb +0 -66
  181. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +0 -410
  182. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +0 -409
  183. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -416
  184. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -416
  185. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -82
  186. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
  187. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -18
  188. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +0 -410
  189. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +0 -409
  190. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +0 -416
  191. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +0 -416
  192. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -83
  193. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  194. data/spec/rspec/core/hooks_spec.rb +0 -250
  195. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  196. data/spec/rspec/core/let_spec.rb +0 -55
  197. data/spec/rspec/core/metadata_spec.rb +0 -447
  198. data/spec/rspec/core/option_parser_spec.rb +0 -166
  199. data/spec/rspec/core/pending_example_spec.rb +0 -220
  200. data/spec/rspec/core/project_initializer_spec.rb +0 -130
  201. data/spec/rspec/core/rake_task_spec.rb +0 -138
  202. data/spec/rspec/core/reporter_spec.rb +0 -103
  203. data/spec/rspec/core/resources/a_bar.rb +0 -0
  204. data/spec/rspec/core/resources/a_foo.rb +0 -0
  205. data/spec/rspec/core/resources/a_spec.rb +0 -1
  206. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  207. data/spec/rspec/core/resources/formatter_specs.rb +0 -60
  208. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  209. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  210. data/spec/rspec/core/ruby_project_spec.rb +0 -24
  211. data/spec/rspec/core/runner_spec.rb +0 -81
  212. data/spec/rspec/core/shared_context_spec.rb +0 -67
  213. data/spec/rspec/core/shared_example_group_spec.rb +0 -84
  214. data/spec/rspec/core/subject_spec.rb +0 -244
  215. data/spec/rspec/core/world_spec.rb +0 -144
  216. data/spec/rspec/core_spec.rb +0 -35
  217. data/spec/spec_helper.rb +0 -98
  218. data/spec/support/config_options_helper.rb +0 -24
  219. data/spec/support/helper_methods.rb +0 -5
  220. data/spec/support/matchers.rb +0 -65
  221. data/spec/support/shared_example_groups.rb +0 -41
  222. data/spec/support/spec_files.rb +0 -44
@@ -1,462 +1,151 @@
1
- require 'erb'
2
- require 'rspec/core/formatters/base_text_formatter'
1
+ RSpec::Support.require_rspec_core "formatters/base_text_formatter"
2
+ RSpec::Support.require_rspec_core "formatters/html_printer"
3
3
 
4
4
  module RSpec
5
5
  module Core
6
6
  module Formatters
7
- class HtmlFormatter < BaseTextFormatter
8
- include ERB::Util # for the #h method
7
+ # @private
8
+ class HtmlFormatter < BaseFormatter
9
+ Formatters.register self, :start, :example_group_started, :start_dump,
10
+ :example_started, :example_passed, :example_failed,
11
+ :example_pending, :dump_summary
9
12
 
10
13
  def initialize(output)
11
14
  super(output)
15
+ @failed_examples = []
12
16
  @example_group_number = 0
13
17
  @example_number = 0
14
18
  @header_red = nil
19
+ @printer = HtmlPrinter.new(output)
15
20
  end
16
21
 
17
- private
18
- def method_missing(m, *a, &b)
19
- # no-op
22
+ def start(notification)
23
+ super
24
+ @printer.print_html_start
25
+ @printer.flush
20
26
  end
21
27
 
22
- public
23
- def message(message)
24
- end
25
-
26
- # The number of the currently running example_group
27
- def example_group_number
28
- @example_group_number
29
- end
30
-
31
- # The number of the currently running example (a global counter)
32
- def example_number
33
- @example_number
34
- end
35
-
36
- def start(example_count)
37
- super(example_count)
38
- @output.puts html_header
39
- @output.puts report_header
40
- @output.flush
41
- end
42
-
43
- def example_group_started(example_group)
44
- super(example_group)
28
+ def example_group_started(notification)
29
+ super
45
30
  @example_group_red = false
46
31
  @example_group_number += 1
47
- unless example_group_number == 1
48
- @output.puts " </dl>"
49
- @output.puts "</div>"
50
- end
51
- @output.puts "<div id=\"div_group_#{example_group_number}\" class=\"example_group passed\">"
52
- @output.puts " <dl #{current_indentation}>"
53
- @output.puts " <dt id=\"example_group_#{example_group_number}\" class=\"passed\">#{h(example_group.description)}</dt>"
54
- @output.flush
32
+
33
+ @printer.print_example_group_end unless example_group_number == 1
34
+ @printer.print_example_group_start(example_group_number,
35
+ notification.group.description,
36
+ notification.group.parent_groups.size)
37
+ @printer.flush
55
38
  end
56
39
 
57
- def start_dump
58
- @output.puts " </dl>"
59
- @output.puts "</div>"
60
- @output.flush
40
+ def start_dump(_notification)
41
+ @printer.print_example_group_end
42
+ @printer.flush
61
43
  end
62
44
 
63
- def example_started(example)
64
- super(example)
45
+ def example_started(_notification)
65
46
  @example_number += 1
66
47
  end
67
48
 
68
- def example_passed(example)
69
- move_progress
70
- @output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span><span class='duration'>#{sprintf("%.5f", example.execution_result[:run_time])}s</span></dd>"
71
- @output.flush
49
+ def example_passed(passed)
50
+ @printer.move_progress(percent_done)
51
+ @printer.print_example_passed(passed.example.description, passed.example.execution_result.run_time)
52
+ @printer.flush
72
53
  end
73
54
 
74
- def example_failed(example)
75
- super(example)
76
- exception = example.metadata[:execution_result][:exception]
77
- extra = extra_failure_content(exception)
78
- @output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red
79
- @header_red = true
80
- @output.puts " <script type=\"text/javascript\">makeRed('div_group_#{example_group_number}');</script>" unless @example_group_red
81
- @output.puts " <script type=\"text/javascript\">makeRed('example_group_#{example_group_number}');</script>" unless @example_group_red
82
- @example_group_red = true
83
- move_progress
84
- @output.puts " <dd class=\"example #{exception.pending_fixed? ? 'pending_fixed' : 'failed'}\">"
85
- @output.puts " <span class=\"failed_spec_name\">#{h(example.description)}</span>"
86
- @output.puts " <span class=\"duration\">#{sprintf('%.5f', example.execution_result[:run_time])}s</span>"
87
- @output.puts " <div class=\"failure\" id=\"failure_#{@failed_examples.size}\">"
88
- @output.puts " <div class=\"message\"><pre>#{h(exception.message)}</pre></div>" unless exception.nil?
89
- @output.puts " <div class=\"backtrace\"><pre>#{format_backtrace(exception.backtrace, example).join("\n")}</pre></div>" if exception
90
- @output.puts extra unless extra == ""
91
- @output.puts " </div>"
92
- @output.puts " </dd>"
93
- @output.flush
94
- end
55
+ def example_failed(failure)
56
+ @failed_examples << failure.example
57
+ unless @header_red
58
+ @header_red = true
59
+ @printer.make_header_red
60
+ end
95
61
 
96
- def example_pending(example)
97
- message = example.metadata[:execution_result][:pending_message]
98
- @output.puts " <script type=\"text/javascript\">makeYellow('rspec-header');</script>" unless @header_red
99
- @output.puts " <script type=\"text/javascript\">makeYellow('div_group_#{example_group_number}');</script>" unless @example_group_red
100
- @output.puts " <script type=\"text/javascript\">makeYellow('example_group_#{example_group_number}');</script>" unless @example_group_red
101
- move_progress
102
- @output.puts " <dd class=\"example not_implemented\"><span class=\"not_implemented_spec_name\">#{h(example.description)} (PENDING: #{h(message)})</span></dd>"
103
- @output.flush
104
- end
62
+ unless @example_group_red
63
+ @example_group_red = true
64
+ @printer.make_example_group_header_red(example_group_number)
65
+ end
105
66
 
106
- # Override this method if you wish to output extra HTML for a failed spec. For example, you
107
- # could output links to images or other files produced during the specs.
108
- #
109
- def extra_failure_content(exception)
110
- require 'rspec/core/formatters/snippet_extractor'
111
- backtrace = exception.backtrace.map {|line| backtrace_line(line)}
112
- backtrace.compact!
113
- @snippet_extractor ||= SnippetExtractor.new
114
- " <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
115
- end
67
+ @printer.move_progress(percent_done)
116
68
 
117
- def move_progress
118
- @output.puts " <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>"
119
- @output.flush
120
- end
69
+ example = failure.example
121
70
 
122
- def percent_done
123
- result = 100.0
124
- if @example_count > 0
125
- result = ((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0
126
- end
127
- result
128
- end
71
+ exception = failure.exception
72
+ message_lines = failure.fully_formatted_lines(nil, RSpec::Core::Notifications::NullColorizer)
73
+ exception_details = if exception
74
+ {
75
+ # drop 2 removes the description (regardless of newlines) and leading blank line
76
+ :message => message_lines.drop(2).join("\n"),
77
+ :backtrace => failure.formatted_backtrace.join("\n"),
78
+ }
79
+ end
80
+ extra = extra_failure_content(failure)
129
81
 
130
- def dump_failures
82
+ @printer.print_example_failed(
83
+ example.execution_result.pending_fixed,
84
+ example.description,
85
+ example.execution_result.run_time,
86
+ @failed_examples.size,
87
+ exception_details,
88
+ (extra == "") ? false : extra
89
+ )
90
+ @printer.flush
131
91
  end
132
92
 
133
- def dump_pending
134
- end
93
+ def example_pending(pending)
94
+ example = pending.example
135
95
 
136
- def dump_summary(duration, example_count, failure_count, pending_count)
137
- # TODO - kill dry_run?
138
- if dry_run?
139
- totals = "This was a dry-run"
140
- else
141
- totals = "#{example_count} example#{'s' unless example_count == 1}, "
142
- totals << "#{failure_count} failure#{'s' unless failure_count == 1}"
143
- totals << ", #{pending_count} pending" if pending_count > 0
144
- end
145
- @output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{sprintf("%.5f", duration)} seconds</strong>\";</script>"
146
- @output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>"
147
- @output.puts "</div>"
148
- @output.puts "</div>"
149
- @output.puts "</body>"
150
- @output.puts "</html>"
151
- @output.flush
152
- end
153
-
154
- def current_indentation
155
- "style=\"margin-left: #{(example_group.ancestors.size - 1) * 15}px;\""
96
+ @printer.make_header_yellow unless @header_red
97
+ @printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
98
+ @printer.move_progress(percent_done)
99
+ @printer.print_example_pending(example.description, example.execution_result.pending_message)
100
+ @printer.flush
156
101
  end
157
102
 
158
- def html_header
159
- <<-EOF
160
- <?xml version="1.0" encoding="UTF-8"?>
161
- <!DOCTYPE html
162
- PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
163
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
164
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
165
- <head>
166
- <title>RSpec results</title>
167
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
168
- <meta http-equiv="Expires" content="-1" />
169
- <meta http-equiv="Pragma" content="no-cache" />
170
- <style type="text/css">
171
- body {
172
- margin: 0;
173
- padding: 0;
174
- background: #fff;
175
- font-size: 80%;
176
- }
177
- </style>
178
- <script type="text/javascript">
179
- // <![CDATA[
180
- #{global_scripts}
181
- // ]]>
182
- </script>
183
- <style type="text/css">
184
- #{global_styles}
185
- </style>
186
- </head>
187
- <body>
188
- EOF
103
+ def dump_summary(summary)
104
+ @printer.print_summary(
105
+ summary.duration,
106
+ summary.example_count,
107
+ summary.failure_count,
108
+ summary.pending_count
109
+ )
110
+ @printer.flush
189
111
  end
190
112
 
191
- def report_header
192
- <<-EOF
193
- <div class="rspec-report">
194
-
195
- <div id="rspec-header">
196
- <div id="label">
197
- <h1>RSpec Code Examples</h1>
198
- </div>
199
-
200
- <div id="display-filters">
201
- <input id="passed_checkbox" name="passed_checkbox" type="checkbox" checked onchange="apply_filters()" value="1"> <label for="passed_checkbox">Passed</label>
202
- <input id="failed_checkbox" name="failed_checkbox" type="checkbox" checked onchange="apply_filters()" value="2"> <label for="failed_checkbox">Failed</label>
203
- <input id="pending_checkbox" name="pending_checkbox" type="checkbox" checked onchange="apply_filters()" value="3"> <label for="pending_checkbox">Pending</label>
204
- </div>
113
+ private
205
114
 
206
- <div id="summary">
207
- <p id="totals">&nbsp;</p>
208
- <p id="duration">&nbsp;</p>
209
- </div>
210
- </div>
115
+ # If these methods are declared with attr_reader Ruby will issue a
116
+ # warning because they are private.
117
+ # rubocop:disable Style/TrivialAccessors
211
118
 
212
-
213
- <div class="results">
214
- EOF
119
+ # The number of the currently running example_group.
120
+ def example_group_number
121
+ @example_group_number
215
122
  end
216
123
 
217
- def global_scripts
218
- <<-EOF
219
-
220
- function addClass(element_id, classname) {
221
- document.getElementById(element_id).className += (" " + classname);
222
- }
223
-
224
- function removeClass(element_id, classname) {
225
- var elem = document.getElementById(element_id);
226
- var classlist = elem.className.replace(classname,'');
227
- elem.className = classlist;
228
- }
229
-
230
- function moveProgressBar(percentDone) {
231
- document.getElementById("rspec-header").style.width = percentDone +"%";
232
- }
233
-
234
- function makeRed(element_id) {
235
- removeClass(element_id, 'passed');
236
- removeClass(element_id, 'not_implemented');
237
- addClass(element_id,'failed');
238
- }
239
-
240
- function makeYellow(element_id) {
241
- var elem = document.getElementById(element_id);
242
- if (elem.className.indexOf("failed") == -1) { // class doesn't includes failed
243
- if (elem.className.indexOf("not_implemented") == -1) { // class doesn't include not_implemented
244
- removeClass(element_id, 'passed');
245
- addClass(element_id,'not_implemented');
246
- }
247
- }
248
- }
249
-
250
- function apply_filters() {
251
- var passed_filter = document.getElementById('passed_checkbox').checked;
252
- var failed_filter = document.getElementById('failed_checkbox').checked;
253
- var pending_filter = document.getElementById('pending_checkbox').checked;
254
-
255
- assign_display_style("example passed", passed_filter);
256
- assign_display_style("example failed", failed_filter);
257
- assign_display_style("example not_implemented", pending_filter);
258
-
259
- assign_display_style_for_group("example_group passed", passed_filter);
260
- assign_display_style_for_group("example_group not_implemented", pending_filter, pending_filter || passed_filter);
261
- assign_display_style_for_group("example_group failed", failed_filter, failed_filter || pending_filter || passed_filter);
262
- }
263
-
264
- function get_display_style(display_flag) {
265
- var style_mode = 'none';
266
- if (display_flag == true) {
267
- style_mode = 'block';
268
- }
269
- return style_mode;
270
- }
271
-
272
- function assign_display_style(classname, display_flag) {
273
- var style_mode = get_display_style(display_flag);
274
- var elems = document.getElementsByClassName(classname)
275
- for (var i=0; i<elems.length;i++) {
276
- elems[i].style.display = style_mode;
277
- }
278
- }
279
-
280
- function assign_display_style_for_group(classname, display_flag, subgroup_flag) {
281
- var display_style_mode = get_display_style(display_flag);
282
- var subgroup_style_mode = get_display_style(subgroup_flag);
283
- var elems = document.getElementsByClassName(classname)
284
- for (var i=0; i<elems.length;i++) {
285
- var style_mode = display_style_mode;
286
- if ((display_flag != subgroup_flag) && (elems[i].getElementsByTagName('dt')[0].innerHTML.indexOf(", ") != -1)) {
287
- elems[i].style.display = subgroup_style_mode;
288
- } else {
289
- elems[i].style.display = display_style_mode;
290
- }
291
- }
292
- }
293
- EOF
124
+ # The number of the currently running example (a global counter).
125
+ def example_number
126
+ @example_number
294
127
  end
128
+ # rubocop:enable Style/TrivialAccessors
295
129
 
296
- def global_styles
297
- <<-EOF
298
- #rspec-header {
299
- background: #65C400; color: #fff; height: 4em;
300
- }
301
-
302
- .rspec-report h1 {
303
- margin: 0px 10px 0px 10px;
304
- padding: 10px;
305
- font-family: "Lucida Grande", Helvetica, sans-serif;
306
- font-size: 1.8em;
307
- position: absolute;
308
- }
309
-
310
- #label {
311
- float:left;
312
- }
313
-
314
- #display-filters {
315
- float:left;
316
- padding: 28px 0 0 40%;
317
- font-family: "Lucida Grande", Helvetica, sans-serif;
318
- }
319
-
320
- #summary {
321
- float:right;
322
- padding: 5px 10px;
323
- font-family: "Lucida Grande", Helvetica, sans-serif;
324
- text-align: right;
325
- }
326
-
327
- #summary p {
328
- margin: 0 0 0 2px;
329
- }
330
-
331
- #summary #totals {
332
- font-size: 1.2em;
333
- }
334
-
335
- .example_group {
336
- margin: 0 10px 5px;
337
- background: #fff;
338
- }
339
-
340
- dl {
341
- margin: 0; padding: 0 0 5px;
342
- font: normal 11px "Lucida Grande", Helvetica, sans-serif;
343
- }
344
-
345
- dt {
346
- padding: 3px;
347
- background: #65C400;
348
- color: #fff;
349
- font-weight: bold;
350
- }
351
-
352
- dd {
353
- margin: 5px 0 5px 5px;
354
- padding: 3px 3px 3px 18px;
355
- }
356
-
357
- dd .duration {
358
- padding-left: 5px;
359
- text-align: right;
360
- right: 0px;
361
- float:right;
362
- }
363
-
364
- dd.example.passed {
365
- border-left: 5px solid #65C400;
366
- border-bottom: 1px solid #65C400;
367
- background: #DBFFB4; color: #3D7700;
368
- }
369
-
370
- dd.example.not_implemented {
371
- border-left: 5px solid #FAF834;
372
- border-bottom: 1px solid #FAF834;
373
- background: #FCFB98; color: #131313;
374
- }
375
-
376
- dd.example.pending_fixed {
377
- border-left: 5px solid #0000C2;
378
- border-bottom: 1px solid #0000C2;
379
- color: #0000C2; background: #D3FBFF;
380
- }
381
-
382
- dd.example.failed {
383
- border-left: 5px solid #C20000;
384
- border-bottom: 1px solid #C20000;
385
- color: #C20000; background: #FFFBD3;
386
- }
387
-
388
-
389
- dt.not_implemented {
390
- color: #000000; background: #FAF834;
391
- }
392
-
393
- dt.pending_fixed {
394
- color: #FFFFFF; background: #C40D0D;
395
- }
396
-
397
- dt.failed {
398
- color: #FFFFFF; background: #C40D0D;
399
- }
400
-
401
-
402
- #rspec-header.not_implemented {
403
- color: #000000; background: #FAF834;
404
- }
405
-
406
- #rspec-header.pending_fixed {
407
- color: #FFFFFF; background: #C40D0D;
408
- }
409
-
410
- #rspec-header.failed {
411
- color: #FFFFFF; background: #C40D0D;
412
- }
413
-
414
-
415
- .backtrace {
416
- color: #000;
417
- font-size: 12px;
418
- }
419
-
420
- a {
421
- color: #BE5C00;
422
- }
423
-
424
- /* Ruby code, style similar to vibrant ink */
425
- .ruby {
426
- font-size: 12px;
427
- font-family: monospace;
428
- color: white;
429
- background-color: black;
430
- padding: 0.1em 0 0.2em 0;
431
- }
432
-
433
- .ruby .keyword { color: #FF6600; }
434
- .ruby .constant { color: #339999; }
435
- .ruby .attribute { color: white; }
436
- .ruby .global { color: white; }
437
- .ruby .module { color: white; }
438
- .ruby .class { color: white; }
439
- .ruby .string { color: #66FF00; }
440
- .ruby .ident { color: white; }
441
- .ruby .method { color: #FFCC00; }
442
- .ruby .number { color: white; }
443
- .ruby .char { color: white; }
444
- .ruby .comment { color: #9933CC; }
445
- .ruby .symbol { color: white; }
446
- .ruby .regex { color: #44B4CC; }
447
- .ruby .punct { color: white; }
448
- .ruby .escape { color: white; }
449
- .ruby .interp { color: white; }
450
- .ruby .expr { color: white; }
130
+ def percent_done
131
+ result = 100.0
132
+ if @example_count > 0
133
+ result = (((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0).to_f
134
+ end
135
+ result
136
+ end
451
137
 
452
- .ruby .offending { background-color: gray; }
453
- .ruby .linenum {
454
- width: 75px;
455
- padding: 0.1em 1em 0.2em 0;
456
- color: #000000;
457
- background-color: #FFFBD3;
458
- }
459
- EOF
138
+ # Override this method if you wish to output extra HTML for a failed
139
+ # spec. For example, you could output links to images or other files
140
+ # produced during the specs.
141
+ def extra_failure_content(failure)
142
+ RSpec::Support.require_rspec_core "formatters/html_snippet_extractor"
143
+ backtrace = (failure.exception.backtrace || []).map do |line|
144
+ RSpec.configuration.backtrace_formatter.backtrace_line(line)
145
+ end
146
+ backtrace.compact!
147
+ @snippet_extractor ||= HtmlSnippetExtractor.new
148
+ " <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
460
149
  end
461
150
  end
462
151
  end