rspec-core 2.99.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +1 -0
  4. data/Changelog.md +339 -1
  5. data/License.txt +1 -0
  6. data/README.md +19 -37
  7. data/exe/rspec +2 -23
  8. data/lib/rspec/core/backport_random.rb +336 -0
  9. data/lib/rspec/core/backtrace_formatter.rb +70 -0
  10. data/lib/rspec/core/configuration.rb +479 -577
  11. data/lib/rspec/core/configuration_options.rb +71 -54
  12. data/lib/rspec/core/drb.rb +111 -0
  13. data/lib/rspec/core/dsl.rb +86 -18
  14. data/lib/rspec/core/example.rb +267 -119
  15. data/lib/rspec/core/example_group.rb +381 -393
  16. data/lib/rspec/core/filter_manager.rb +133 -114
  17. data/lib/rspec/core/flat_map.rb +18 -0
  18. data/lib/rspec/core/formatters/base_formatter.rb +51 -125
  19. data/lib/rspec/core/formatters/base_text_formatter.rb +34 -286
  20. data/lib/rspec/core/formatters/console_codes.rb +24 -1
  21. data/lib/rspec/core/formatters/deprecation_formatter.rb +25 -26
  22. data/lib/rspec/core/formatters/documentation_formatter.rb +27 -25
  23. data/lib/rspec/core/formatters/helpers.rb +14 -36
  24. data/lib/rspec/core/formatters/html_formatter.rb +58 -65
  25. data/lib/rspec/core/formatters/html_printer.rb +12 -18
  26. data/lib/rspec/core/formatters/json_formatter.rb +54 -31
  27. data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
  28. data/lib/rspec/core/formatters/progress_formatter.rb +11 -15
  29. data/lib/rspec/core/formatters/snippet_extractor.rb +22 -11
  30. data/lib/rspec/core/formatters.rb +90 -43
  31. data/lib/rspec/core/hooks.rb +325 -270
  32. data/lib/rspec/core/memoized_helpers.rb +45 -156
  33. data/lib/rspec/core/metadata.rb +284 -236
  34. data/lib/rspec/core/metadata_filter.rb +86 -0
  35. data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
  36. data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
  37. data/lib/rspec/core/mocking_adapters/null.rb +12 -0
  38. data/lib/rspec/core/mocking_adapters/rr.rb +29 -0
  39. data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
  40. data/lib/rspec/core/notifications.rb +511 -0
  41. data/lib/rspec/core/option_parser.rb +49 -74
  42. data/lib/rspec/core/ordering.rb +156 -0
  43. data/lib/rspec/core/pending.rb +94 -96
  44. data/lib/rspec/core/project_initializer/.rspec +3 -0
  45. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +78 -0
  46. data/lib/rspec/core/project_initializer.rb +24 -64
  47. data/lib/rspec/core/rake_task.rb +44 -130
  48. data/lib/rspec/core/reporter.rb +76 -59
  49. data/lib/rspec/core/ruby_project.rb +2 -1
  50. data/lib/rspec/core/runner.rb +117 -52
  51. data/lib/rspec/core/shared_context.rb +10 -10
  52. data/lib/rspec/core/shared_example_group.rb +108 -121
  53. data/lib/rspec/core/version.rb +3 -1
  54. data/lib/rspec/core/warnings.rb +40 -0
  55. data/lib/rspec/core/world.rb +66 -10
  56. data/lib/rspec/core.rb +64 -104
  57. data.tar.gz.sig +3 -0
  58. metadata +75 -322
  59. metadata.gz.sig +1 -0
  60. data/exe/autospec +0 -13
  61. data/features/Autotest.md +0 -38
  62. data/features/README.md +0 -17
  63. data/features/Upgrade.md +0 -364
  64. data/features/command_line/README.md +0 -28
  65. data/features/command_line/example_name_option.feature +0 -97
  66. data/features/command_line/exit_status.feature +0 -82
  67. data/features/command_line/format_option.feature +0 -75
  68. data/features/command_line/init.feature +0 -18
  69. data/features/command_line/line_number_appended_to_path.feature +0 -140
  70. data/features/command_line/line_number_option.feature +0 -53
  71. data/features/command_line/order.feature +0 -26
  72. data/features/command_line/pattern_option.feature +0 -49
  73. data/features/command_line/rake_task.feature +0 -122
  74. data/features/command_line/require_option.feature +0 -43
  75. data/features/command_line/ruby.feature +0 -22
  76. data/features/command_line/tag.feature +0 -98
  77. data/features/command_line/warnings_option.feature +0 -29
  78. data/features/configuration/alias_example_to.feature +0 -48
  79. data/features/configuration/backtrace_clean_patterns.feature +0 -102
  80. data/features/configuration/custom_settings.feature +0 -84
  81. data/features/configuration/default_path.feature +0 -38
  82. data/features/configuration/deprecation_stream.feature +0 -58
  83. data/features/configuration/fail_fast.feature +0 -77
  84. data/features/configuration/failure_exit_code.feature +0 -36
  85. data/features/configuration/order_and_seed.feature +0 -3
  86. data/features/configuration/output_stream.feature +0 -24
  87. data/features/configuration/pattern.feature +0 -38
  88. data/features/configuration/profile.feature +0 -220
  89. data/features/configuration/read_options_from_file.feature +0 -90
  90. data/features/configuration/run_all_when_everything_filtered.feature +0 -76
  91. data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
  92. data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
  93. data/features/example_groups/basic_structure.feature +0 -55
  94. data/features/example_groups/shared_context.feature +0 -74
  95. data/features/example_groups/shared_examples.feature +0 -294
  96. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -197
  97. data/features/filtering/exclusion_filters.feature +0 -138
  98. data/features/filtering/if_and_unless.feature +0 -168
  99. data/features/filtering/inclusion_filters.feature +0 -105
  100. data/features/formatters/configurable_colors.feature +0 -31
  101. data/features/formatters/custom_formatter.feature +0 -36
  102. data/features/formatters/json_formatter.feature +0 -30
  103. data/features/formatters/text_formatter.feature +0 -46
  104. data/features/helper_methods/arbitrary_methods.feature +0 -40
  105. data/features/helper_methods/let.feature +0 -50
  106. data/features/helper_methods/modules.feature +0 -149
  107. data/features/hooks/around_hooks.feature +0 -343
  108. data/features/hooks/before_and_after_hooks.feature +0 -427
  109. data/features/hooks/filtering.feature +0 -234
  110. data/features/metadata/current_example.feature +0 -56
  111. data/features/metadata/described_class.feature +0 -17
  112. data/features/metadata/user_defined.feature +0 -113
  113. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  114. data/features/mock_framework_integration/use_flexmock.feature +0 -96
  115. data/features/mock_framework_integration/use_mocha.feature +0 -97
  116. data/features/mock_framework_integration/use_rr.feature +0 -98
  117. data/features/mock_framework_integration/use_rspec.feature +0 -97
  118. data/features/pending/pending_examples.feature +0 -229
  119. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  120. data/features/step_definitions/additional_cli_steps.rb +0 -49
  121. data/features/subject/attribute_of_subject.feature +0 -124
  122. data/features/subject/explicit_subject.feature +0 -101
  123. data/features/subject/implicit_subject.feature +0 -63
  124. data/features/subject/one_liner_syntax.feature +0 -71
  125. data/features/support/env.rb +0 -14
  126. data/features/support/rubinius.rb +0 -6
  127. data/lib/autotest/discover.rb +0 -10
  128. data/lib/autotest/rspec2.rb +0 -77
  129. data/lib/rspec/core/backtrace_cleaner.rb +0 -46
  130. data/lib/rspec/core/backward_compatibility.rb +0 -55
  131. data/lib/rspec/core/caller_filter.rb +0 -60
  132. data/lib/rspec/core/command_line.rb +0 -47
  133. data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
  134. data/lib/rspec/core/deprecation.rb +0 -26
  135. data/lib/rspec/core/drb_command_line.rb +0 -26
  136. data/lib/rspec/core/drb_options.rb +0 -87
  137. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  138. data/lib/rspec/core/extensions/kernel.rb +0 -9
  139. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  140. data/lib/rspec/core/extensions/ordered.rb +0 -27
  141. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  142. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  143. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  144. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  145. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  146. data/lib/rspec/core/mocking/with_rspec.rb +0 -27
  147. data/lib/rspec/core/shared_example_group/collection.rb +0 -45
  148. data/spec/autotest/discover_spec.rb +0 -49
  149. data/spec/autotest/failed_results_re_spec.rb +0 -45
  150. data/spec/autotest/rspec_spec.rb +0 -133
  151. data/spec/command_line/order_spec.rb +0 -204
  152. data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
  153. data/spec/rspec/core/caller_filter_spec.rb +0 -58
  154. data/spec/rspec/core/command_line_spec.rb +0 -127
  155. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  156. data/spec/rspec/core/configuration_options_spec.rb +0 -417
  157. data/spec/rspec/core/configuration_spec.rb +0 -2072
  158. data/spec/rspec/core/deprecation_spec.rb +0 -27
  159. data/spec/rspec/core/deprecations_spec.rb +0 -59
  160. data/spec/rspec/core/drb_command_line_spec.rb +0 -102
  161. data/spec/rspec/core/drb_options_spec.rb +0 -193
  162. data/spec/rspec/core/dsl_spec.rb +0 -25
  163. data/spec/rspec/core/example_group_spec.rb +0 -1337
  164. data/spec/rspec/core/example_spec.rb +0 -502
  165. data/spec/rspec/core/filter_manager_spec.rb +0 -246
  166. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -108
  167. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -524
  168. data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
  169. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -263
  170. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -89
  171. data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
  172. data/spec/rspec/core/formatters/html_formatted.html +0 -397
  173. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -131
  174. data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -115
  175. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
  176. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
  177. data/spec/rspec/core/formatters/text_mate_formatted.html +0 -397
  178. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
  179. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  180. data/spec/rspec/core/hooks_spec.rb +0 -269
  181. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  182. data/spec/rspec/core/memoized_helpers_spec.rb +0 -776
  183. data/spec/rspec/core/metadata_spec.rb +0 -514
  184. data/spec/rspec/core/option_parser_spec.rb +0 -297
  185. data/spec/rspec/core/pending_example_spec.rb +0 -260
  186. data/spec/rspec/core/pending_spec.rb +0 -27
  187. data/spec/rspec/core/project_initializer_spec.rb +0 -130
  188. data/spec/rspec/core/rake_task_spec.rb +0 -202
  189. data/spec/rspec/core/reporter_spec.rb +0 -167
  190. data/spec/rspec/core/resources/a_bar.rb +0 -0
  191. data/spec/rspec/core/resources/a_foo.rb +0 -0
  192. data/spec/rspec/core/resources/a_spec.rb +0 -1
  193. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  194. data/spec/rspec/core/resources/formatter_specs.rb +0 -60
  195. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  196. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  197. data/spec/rspec/core/ruby_project_spec.rb +0 -26
  198. data/spec/rspec/core/runner_spec.rb +0 -82
  199. data/spec/rspec/core/shared_context_spec.rb +0 -114
  200. data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -70
  201. data/spec/rspec/core/shared_example_group_spec.rb +0 -138
  202. data/spec/rspec/core/world_spec.rb +0 -142
  203. data/spec/rspec/core_spec.rb +0 -108
  204. data/spec/spec_helper.rb +0 -135
  205. data/spec/support/config_options_helper.rb +0 -15
  206. data/spec/support/helper_methods.rb +0 -55
  207. data/spec/support/in_sub_process.rb +0 -37
  208. data/spec/support/isolate_load_path_mutation.rb +0 -6
  209. data/spec/support/isolated_directory.rb +0 -10
  210. data/spec/support/isolated_home_directory.rb +0 -16
  211. data/spec/support/matchers.rb +0 -65
  212. data/spec/support/mathn_integration_support.rb +0 -12
  213. data/spec/support/sandboxed_mock_space.rb +0 -116
  214. data/spec/support/shared_example_groups.rb +0 -42
  215. data/spec/support/silence_dsl_deprecations.rb +0 -32
  216. data/spec/support/spec_files.rb +0 -44
@@ -1,48 +1,26 @@
1
1
  module RSpec
2
2
  module Core
3
- module BacktraceFormatter
4
- extend self
5
-
6
- def format_backtrace(backtrace, options = {})
7
- return "" unless backtrace
8
- return backtrace if options[:full_backtrace] == true
9
-
10
- if at_exit_index = backtrace.index(RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE)
11
- backtrace = backtrace[0, at_exit_index]
12
- end
13
-
14
- cleansed = backtrace.map { |line| backtrace_line(line) }.compact
15
- cleansed.empty? ? backtrace : cleansed
16
- end
17
-
18
- protected
19
-
20
- def backtrace_line(line)
21
- return nil if RSpec.configuration.backtrace_formatter.exclude?(line)
22
- RSpec::Core::Metadata::relative_path(line)
23
- rescue SecurityError
24
- nil
25
- end
26
- end
27
-
28
3
  module Formatters
4
+ # Formatters helpers
29
5
  module Helpers
30
- include BacktraceFormatter
31
6
 
7
+ # @private
32
8
  SUB_SECOND_PRECISION = 5
9
+
10
+ # @private
33
11
  DEFAULT_PRECISION = 2
34
12
 
35
13
  # @api private
36
14
  #
37
15
  # Formats seconds into a human-readable string.
38
16
  #
39
- # @param [Float, Fixnum] duration in seconds
17
+ # @param duration [Float, Fixnum] in seconds
40
18
  # @return [String] human-readable time
41
19
  #
42
20
  # @example
43
21
  # format_duration(1) #=> "1 minute 1 second"
44
22
  # format_duration(135.14) #=> "2 minutes 15.14 seconds"
45
- def format_duration(duration)
23
+ def self.format_duration(duration)
46
24
  precision = case
47
25
  when duration < 1; SUB_SECOND_PRECISION
48
26
  when duration < 120; DEFAULT_PRECISION
@@ -65,7 +43,7 @@ module RSpec
65
43
  # Formats seconds to have 5 digits of precision with trailing zeros removed if the number
66
44
  # is less than 1 or with 2 digits of precision if the number is greater than zero.
67
45
  #
68
- # @param [Float] float
46
+ # @param float [Float]
69
47
  # @return [String] formatted float
70
48
  #
71
49
  # @example
@@ -76,7 +54,7 @@ module RSpec
76
54
  # The precision used is set in {Helpers::SUB_SECOND_PRECISION} and {Helpers::DEFAULT_PRECISION}.
77
55
  #
78
56
  # @see #strip_trailing_zeroes
79
- def format_seconds(float, precision = nil)
57
+ def self.format_seconds(float, precision = nil)
80
58
  precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
81
59
  formatted = sprintf("%.#{precision}f", float)
82
60
  strip_trailing_zeroes(formatted)
@@ -86,25 +64,25 @@ module RSpec
86
64
  #
87
65
  # Remove trailing zeros from a string.
88
66
  #
89
- # @param [String] string string with trailing zeros
67
+ # @param string [String] string with trailing zeros
90
68
  # @return [String] string with trailing zeros removed
91
- def strip_trailing_zeroes(string)
69
+ def self.strip_trailing_zeroes(string)
92
70
  stripped = string.sub(/[^1-9]+$/, '')
93
71
  stripped.empty? ? "0" : stripped
94
72
  end
73
+ private_class_method :strip_trailing_zeroes
95
74
 
96
75
  # @api private
97
76
  #
98
77
  # Pluralize a word based on a count.
99
78
  #
100
- # @param [Fixnum] count number of objects
101
- # @param [String] string word to be pluralized
79
+ # @param count [Fixnum] number of objects
80
+ # @param string [String] word to be pluralized
102
81
  # @return [String] pluralized word
103
- def pluralize(count, string)
82
+ def self.pluralize(count, string)
104
83
  "#{count} #{string}#{'s' unless count.to_f == 1}"
105
84
  end
106
85
  end
107
-
108
86
  end
109
87
  end
110
88
  end
@@ -1,75 +1,59 @@
1
- require 'rspec/core/formatters/base_text_formatter'
2
- require 'rspec/core/formatters/html_printer'
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
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
8
12
 
9
13
  def initialize(output)
10
14
  super(output)
15
+ @failed_examples = []
11
16
  @example_group_number = 0
12
17
  @example_number = 0
13
18
  @header_red = nil
14
19
  @printer = HtmlPrinter.new(output)
15
20
  end
16
21
 
17
- private
18
- def method_missing(m, *a, &b)
19
- # no-op
20
- end
21
-
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)
22
+ def start(notification)
23
+ super
38
24
  @printer.print_html_start
39
25
  @printer.flush
40
26
  end
41
27
 
42
- def example_group_started(example_group)
43
- super(example_group)
28
+ def example_group_started(notification)
29
+ super
44
30
  @example_group_red = false
45
31
  @example_group_number += 1
46
32
 
47
33
  unless example_group_number == 1
48
34
  @printer.print_example_group_end
49
35
  end
50
- @printer.print_example_group_start( example_group_number, example_group.description, example_group.parent_groups.size )
36
+ @printer.print_example_group_start( example_group_number, notification.group.description, notification.group.parent_groups.size )
51
37
  @printer.flush
52
38
  end
53
39
 
54
- def start_dump
40
+ def start_dump(notification)
55
41
  @printer.print_example_group_end
56
42
  @printer.flush
57
43
  end
58
44
 
59
- def example_started(example)
60
- super(example)
45
+ def example_started(notification)
61
46
  @example_number += 1
62
47
  end
63
48
 
64
- def example_passed(example)
49
+ def example_passed(passed)
65
50
  @printer.move_progress(percent_done)
66
- @printer.print_example_passed( example.description, example.execution_result[:run_time] )
51
+ @printer.print_example_passed( passed.example.description, passed.example.execution_result.run_time )
67
52
  @printer.flush
68
53
  end
69
54
 
70
- def example_failed(example)
71
- super(example)
72
-
55
+ def example_failed(failure)
56
+ @failed_examples << failure.example
73
57
  unless @header_red
74
58
  @header_red = true
75
59
  @printer.make_header_red
@@ -82,21 +66,23 @@ module RSpec
82
66
 
83
67
  @printer.move_progress(percent_done)
84
68
 
85
- exception = example.metadata[:execution_result][:exception]
69
+ example = failure.example
70
+
71
+ exception = failure.exception
86
72
  exception_details = if exception
87
73
  {
88
74
  :message => exception.message,
89
- :backtrace => format_backtrace(exception.backtrace, example).join("\n")
75
+ :backtrace => failure.formatted_backtrace.join("\n")
90
76
  }
91
77
  else
92
78
  false
93
79
  end
94
- extra = extra_failure_content(exception)
80
+ extra = extra_failure_content(failure)
95
81
 
96
82
  @printer.print_example_failed(
97
- example.execution_result[:pending_fixed],
83
+ example.execution_result.pending_fixed,
98
84
  example.description,
99
- example.execution_result[:run_time],
85
+ example.execution_result.run_time,
100
86
  @failed_examples.size,
101
87
  exception_details,
102
88
  (extra == "") ? false : extra,
@@ -105,24 +91,36 @@ module RSpec
105
91
  @printer.flush
106
92
  end
107
93
 
108
- def example_pending(example)
94
+ def example_pending(pending)
95
+ example = pending.example
109
96
 
110
97
  @printer.make_header_yellow unless @header_red
111
98
  @printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
112
99
  @printer.move_progress(percent_done)
113
- @printer.print_example_pending( example.description, example.metadata[:execution_result][:pending_message] )
100
+ @printer.print_example_pending( example.description, example.execution_result.pending_message )
114
101
  @printer.flush
115
102
  end
116
103
 
117
- # Override this method if you wish to output extra HTML for a failed spec. For example, you
118
- # could output links to images or other files produced during the specs.
119
- #
120
- def extra_failure_content(exception)
121
- require 'rspec/core/formatters/snippet_extractor'
122
- backtrace = exception.backtrace.map {|line| backtrace_line(line)}
123
- backtrace.compact!
124
- @snippet_extractor ||= SnippetExtractor.new
125
- " <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
104
+ def dump_summary(summary)
105
+ @printer.print_summary(
106
+ summary.duration,
107
+ summary.example_count,
108
+ summary.failure_count,
109
+ summary.pending_count
110
+ )
111
+ @printer.flush
112
+ end
113
+
114
+ private
115
+
116
+ # The number of the currently running example_group
117
+ def example_group_number
118
+ @example_group_number
119
+ end
120
+
121
+ # The number of the currently running example (a global counter)
122
+ def example_number
123
+ @example_number
126
124
  end
127
125
 
128
126
  def percent_done
@@ -133,22 +131,17 @@ module RSpec
133
131
  result
134
132
  end
135
133
 
136
- def dump_failures
137
- end
138
-
139
- def dump_pending
134
+ # Override this method if you wish to output extra HTML for a failed spec. For example, you
135
+ # could output links to images or other files produced during the specs.
136
+ #
137
+ def extra_failure_content(failure)
138
+ RSpec::Support.require_rspec_core "formatters/snippet_extractor"
139
+ backtrace = failure.exception.backtrace.map {|line| RSpec.configuration.backtrace_formatter.backtrace_line(line)}
140
+ backtrace.compact!
141
+ @snippet_extractor ||= SnippetExtractor.new
142
+ " <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
140
143
  end
141
144
 
142
- def dump_summary(duration, example_count, failure_count, pending_count)
143
- @printer.print_summary(
144
- dry_run?,
145
- duration,
146
- example_count,
147
- failure_count,
148
- pending_count
149
- )
150
- @printer.flush
151
- end
152
145
  end
153
146
  end
154
147
  end
@@ -3,6 +3,7 @@ require 'erb'
3
3
  module RSpec
4
4
  module Core
5
5
  module Formatters
6
+ # @private
6
7
  class HtmlPrinter
7
8
  include ERB::Util # for the #h method
8
9
  def initialize(output)
@@ -19,18 +20,18 @@ module RSpec
19
20
  @output.puts "</div>"
20
21
  end
21
22
 
22
- def print_example_group_start( group_id, description, number_of_parents )
23
+ def print_example_group_start(group_id, description, number_of_parents)
23
24
  @output.puts "<div id=\"div_group_#{group_id}\" class=\"example_group passed\">"
24
25
  @output.puts " <dl #{indentation_style(number_of_parents)}>"
25
26
  @output.puts " <dt id=\"example_group_#{group_id}\" class=\"passed\">#{h(description)}</dt>"
26
27
  end
27
28
 
28
- def print_example_passed( description, run_time )
29
+ def print_example_passed(description, run_time)
29
30
  formatted_run_time = sprintf("%.5f", run_time)
30
31
  @output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(description)}</span><span class='duration'>#{formatted_run_time}s</span></dd>"
31
32
  end
32
33
 
33
- def print_example_failed( pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false )
34
+ def print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false)
34
35
  formatted_run_time = sprintf("%.5f", run_time)
35
36
 
36
37
  @output.puts " <dd class=\"example #{pending_fixed ? 'pending_fixed' : 'failed'}\">"
@@ -50,19 +51,14 @@ module RSpec
50
51
  @output.puts " </dd>"
51
52
  end
52
53
 
53
- def print_example_pending( description, pending_message )
54
+ def print_example_pending(description, pending_message)
54
55
  @output.puts " <dd class=\"example not_implemented\"><span class=\"not_implemented_spec_name\">#{h(description)} (PENDING: #{h(pending_message)})</span></dd>"
55
56
  end
56
57
 
57
- def print_summary( was_dry_run, duration, example_count, failure_count, pending_count )
58
- # TODO - kill dry_run?
59
- if was_dry_run
60
- totals = "This was a dry-run"
61
- else
62
- totals = "#{example_count} example#{'s' unless example_count == 1}, "
63
- totals << "#{failure_count} failure#{'s' unless failure_count == 1}"
64
- totals << ", #{pending_count} pending" if pending_count > 0
65
- end
58
+ def print_summary(duration, example_count, failure_count, pending_count)
59
+ totals = "#{example_count} example#{'s' unless example_count == 1}, "
60
+ totals << "#{failure_count} failure#{'s' unless failure_count == 1}"
61
+ totals << ", #{pending_count} pending" if pending_count > 0
66
62
 
67
63
  formatted_duration = sprintf("%.5f", duration)
68
64
 
@@ -78,7 +74,7 @@ module RSpec
78
74
  @output.flush
79
75
  end
80
76
 
81
- def move_progress( percent_done )
77
+ def move_progress(percent_done)
82
78
  @output.puts " <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>"
83
79
  @output.flush
84
80
  end
@@ -101,14 +97,12 @@ module RSpec
101
97
  @output.puts " <script type=\"text/javascript\">makeYellow('example_group_#{group_id}');</script>"
102
98
  end
103
99
 
100
+ private
104
101
 
105
- private
106
-
107
- def indentation_style( number_of_parents )
102
+ def indentation_style(number_of_parents)
108
103
  "style=\"margin-left: #{(number_of_parents - 1) * 15}px;\""
109
104
  end
110
105
 
111
-
112
106
  REPORT_HEADER = <<-EOF
113
107
  <div class="rspec-report">
114
108
 
@@ -1,11 +1,12 @@
1
- require 'rspec/core/formatters/base_formatter'
1
+ RSpec::Support.require_rspec_core "formatters/base_formatter"
2
2
  require 'json'
3
3
 
4
4
  module RSpec
5
5
  module Core
6
6
  module Formatters
7
-
7
+ # @private
8
8
  class JsonFormatter < BaseFormatter
9
+ Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :close
9
10
 
10
11
  attr_reader :output_hash
11
12
 
@@ -14,40 +15,23 @@ module RSpec
14
15
  @output_hash = {}
15
16
  end
16
17
 
17
- def message(message)
18
- (@output_hash[:messages] ||= []) << message
18
+ def message(notification)
19
+ (@output_hash[:messages] ||= []) << notification.message
19
20
  end
20
21
 
21
- def dump_summary(duration, example_count, failure_count, pending_count)
22
- super(duration, example_count, failure_count, pending_count)
22
+ def dump_summary(summary)
23
23
  @output_hash[:summary] = {
24
- :duration => duration,
25
- :example_count => example_count,
26
- :failure_count => failure_count,
27
- :pending_count => pending_count
24
+ :duration => summary.duration,
25
+ :example_count => summary.example_count,
26
+ :failure_count => summary.failure_count,
27
+ :pending_count => summary.pending_count
28
28
  }
29
- @output_hash[:summary_line] = summary_line(example_count, failure_count, pending_count)
30
- end
31
-
32
- def summary_line(example_count, failure_count, pending_count)
33
- summary = pluralize(example_count, "example")
34
- summary << ", " << pluralize(failure_count, "failure")
35
- summary << ", #{pending_count} pending" if pending_count > 0
36
- summary
29
+ @output_hash[:summary_line] = summary.totals_line
37
30
  end
38
31
 
39
- def stop
40
- super
41
- @output_hash[:examples] = examples.map do |example|
42
- {
43
- :description => example.description,
44
- :full_description => example.full_description,
45
- :status => example.execution_result[:status],
46
- # :example_group,
47
- # :execution_result,
48
- :file_path => example.metadata[:file_path],
49
- :line_number => example.metadata[:line_number],
50
- }.tap do |hash|
32
+ def stop(notification)
33
+ @output_hash[:examples] = notification.examples.map do |example|
34
+ format_example(example).tap do |hash|
51
35
  if e=example.exception
52
36
  hash[:exception] = {
53
37
  :class => e.class.name,
@@ -59,11 +43,50 @@ module RSpec
59
43
  end
60
44
  end
61
45
 
62
- def close
46
+ def close(notification)
63
47
  output.write @output_hash.to_json
64
48
  output.close if IO === output && output != $stdout
65
49
  end
66
50
 
51
+ def dump_profile(profile)
52
+ @output_hash[:profile] = {}
53
+ dump_profile_slowest_examples(profile)
54
+ dump_profile_slowest_example_groups(profile)
55
+ end
56
+
57
+ # @api private
58
+ def dump_profile_slowest_examples(profile)
59
+ @output_hash[:profile] = {}
60
+ sorted_examples = profile.slowest_examples
61
+ @output_hash[:profile][:examples] = sorted_examples.map do |example|
62
+ format_example(example).tap do |hash|
63
+ hash[:run_time] = example.execution_result.run_time
64
+ end
65
+ end
66
+ @output_hash[:profile][:slowest] = profile.slow_duration
67
+ @output_hash[:profile][:total] = profile.duration
68
+ end
69
+
70
+ # @api private
71
+ def dump_profile_slowest_example_groups(profile)
72
+ @output_hash[:profile] ||= {}
73
+ @output_hash[:profile][:groups] = profile.slowest_groups.map do |loc, hash|
74
+ hash.update(:location => loc)
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def format_example(example)
81
+ {
82
+ :description => example.description,
83
+ :full_description => example.full_description,
84
+ :status => example.execution_result.status.to_s,
85
+ :file_path => example.metadata[:file_path],
86
+ :line_number => example.metadata[:line_number],
87
+ :run_time => example.execution_result.run_time
88
+ }
89
+ end
67
90
  end
68
91
  end
69
92
  end
@@ -0,0 +1,67 @@
1
+ RSpec::Support.require_rspec_core "formatters/console_codes"
2
+
3
+ module RSpec
4
+ module Core
5
+ module Formatters
6
+
7
+ # @api private
8
+ # Formatter for providing profile output
9
+ class ProfileFormatter
10
+ Formatters.register self, :dump_profile
11
+
12
+ def initialize(output)
13
+ @output = output
14
+ end
15
+
16
+ # @private
17
+ attr_reader :output
18
+
19
+ # @method dump_profile
20
+ # @api public
21
+ #
22
+ # This method is invoked after the dumping the summary if profiling is
23
+ # enabled.
24
+ #
25
+ # @param profile [ProfileNotification] containing duration, slowest_examples
26
+ # and slowest_example_groups
27
+ def dump_profile(profile)
28
+ dump_profile_slowest_examples(profile)
29
+ dump_profile_slowest_example_groups(profile)
30
+ end
31
+
32
+ private
33
+
34
+ def dump_profile_slowest_examples(profile)
35
+ @output.puts "\nTop #{profile.slowest_examples.size} slowest examples (#{Helpers.format_seconds(profile.slow_duration)} seconds, #{profile.percentage}% of total time):\n"
36
+
37
+ profile.slowest_examples.each do |example|
38
+ @output.puts " #{example.full_description}"
39
+ @output.puts " #{bold(Helpers.format_seconds(example.execution_result.run_time))} #{bold("seconds")} #{format_caller(example.location)}"
40
+ end
41
+ end
42
+
43
+ def dump_profile_slowest_example_groups(profile)
44
+ return if profile.slowest_groups.empty?
45
+
46
+ @output.puts "\nTop #{profile.slowest_groups.size} slowest example groups:"
47
+ profile.slowest_groups.each do |loc, hash|
48
+ average = "#{bold(Helpers.format_seconds(hash[:average]))} #{bold("seconds")} average"
49
+ total = "#{Helpers.format_seconds(hash[:total_time])} seconds"
50
+ count = Helpers.pluralize(hash[:count], "example")
51
+ @output.puts " #{hash[:description]}"
52
+ @output.puts " #{average} (#{total} / #{count}) #{loc}"
53
+ end
54
+ end
55
+
56
+ def format_caller(caller_info)
57
+ RSpec.configuration.backtrace_formatter.backtrace_line(caller_info.to_s.split(':in `block').first)
58
+ end
59
+
60
+ def bold(text)
61
+ ConsoleCodes.wrap(text, :bold)
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,32 +1,28 @@
1
- require 'rspec/core/formatters/base_text_formatter'
1
+ RSpec::Support.require_rspec_core "formatters/base_text_formatter"
2
+
2
3
  module RSpec
3
4
  module Core
4
5
  module Formatters
5
-
6
+ # @private
6
7
  class ProgressFormatter < BaseTextFormatter
8
+ Formatters.register self, :example_passed, :example_pending, :example_failed, :start_dump
7
9
 
8
- def example_passed(example)
9
- super(example)
10
- output.print success_color('.')
10
+ def example_passed(notification)
11
+ output.print ConsoleCodes.wrap('.', :success)
11
12
  end
12
13
 
13
- def example_pending(example)
14
- super(example)
15
- output.print pending_color('*')
14
+ def example_pending(notification)
15
+ output.print ConsoleCodes.wrap('*', :pending)
16
16
  end
17
17
 
18
- def example_failed(example)
19
- super(example)
20
- output.print failure_color('F')
18
+ def example_failed(notification)
19
+ output.print ConsoleCodes.wrap('F', :failure)
21
20
  end
22
21
 
23
- def start_dump
24
- super()
22
+ def start_dump(notification)
25
23
  output.puts
26
24
  end
27
-
28
25
  end
29
-
30
26
  end
31
27
  end
32
28
  end