rspec-core 3.0.0.beta2 → 3.0.0.rc1

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 (201) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +1 -0
  5. data/Changelog.md +297 -57
  6. data/README.md +16 -13
  7. data/lib/rspec/core.rb +55 -84
  8. data/lib/rspec/core/backport_random.rb +35 -3
  9. data/lib/rspec/core/backtrace_formatter.rb +4 -13
  10. data/lib/rspec/core/configuration.rb +330 -114
  11. data/lib/rspec/core/configuration_options.rb +38 -22
  12. data/lib/rspec/core/drb.rb +111 -0
  13. data/lib/rspec/core/dsl.rb +8 -2
  14. data/lib/rspec/core/example.rb +203 -94
  15. data/lib/rspec/core/example_group.rb +344 -316
  16. data/lib/rspec/core/filter_manager.rb +135 -90
  17. data/lib/rspec/core/flat_map.rb +1 -0
  18. data/lib/rspec/core/formatters.rb +50 -14
  19. data/lib/rspec/core/formatters/base_formatter.rb +32 -138
  20. data/lib/rspec/core/formatters/base_text_formatter.rb +32 -253
  21. data/lib/rspec/core/formatters/console_codes.rb +65 -0
  22. data/lib/rspec/core/formatters/deprecation_formatter.rb +24 -15
  23. data/lib/rspec/core/formatters/documentation_formatter.rb +7 -10
  24. data/lib/rspec/core/formatters/helpers.rb +15 -9
  25. data/lib/rspec/core/formatters/html_formatter.rb +17 -16
  26. data/lib/rspec/core/formatters/html_printer.rb +1 -0
  27. data/lib/rspec/core/formatters/json_formatter.rb +18 -20
  28. data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
  29. data/lib/rspec/core/formatters/progress_formatter.rb +6 -7
  30. data/lib/rspec/core/formatters/snippet_extractor.rb +8 -6
  31. data/lib/rspec/core/hooks.rb +131 -125
  32. data/lib/rspec/core/memoized_helpers.rb +31 -26
  33. data/lib/rspec/core/metadata.rb +277 -184
  34. data/lib/rspec/core/metadata_filter.rb +86 -0
  35. data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
  36. data/lib/rspec/core/mocking_adapters/flexmock.rb +1 -1
  37. data/lib/rspec/core/mocking_adapters/mocha.rb +1 -1
  38. data/lib/rspec/core/mocking_adapters/null.rb +1 -1
  39. data/lib/rspec/core/mocking_adapters/rr.rb +2 -1
  40. data/lib/rspec/core/mocking_adapters/rspec.rb +1 -1
  41. data/lib/rspec/core/notifications.rb +435 -24
  42. data/lib/rspec/core/option_parser.rb +16 -25
  43. data/lib/rspec/core/ordering.rb +3 -1
  44. data/lib/rspec/core/pending.rb +57 -33
  45. data/lib/rspec/core/project_initializer.rb +2 -0
  46. data/lib/rspec/core/project_initializer/spec_helper.rb +5 -4
  47. data/lib/rspec/core/rake_task.rb +45 -20
  48. data/lib/rspec/core/reporter.rb +50 -22
  49. data/lib/rspec/core/ruby_project.rb +1 -0
  50. data/lib/rspec/core/runner.rb +93 -39
  51. data/lib/rspec/core/shared_context.rb +7 -5
  52. data/lib/rspec/core/shared_example_group.rb +85 -77
  53. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  54. data/lib/rspec/core/version.rb +3 -1
  55. data/lib/rspec/core/warnings.rb +35 -17
  56. data/lib/rspec/core/world.rb +57 -5
  57. metadata +56 -369
  58. metadata.gz.sig +3 -3
  59. data/features/README.md +0 -13
  60. data/features/Upgrade.md +0 -352
  61. data/features/command_line/README.md +0 -25
  62. data/features/command_line/dry_run.feature +0 -29
  63. data/features/command_line/example_name_option.feature +0 -97
  64. data/features/command_line/exit_status.feature +0 -82
  65. data/features/command_line/fail_fast.feature +0 -26
  66. data/features/command_line/format_option.feature +0 -75
  67. data/features/command_line/init.feature +0 -57
  68. data/features/command_line/line_number_appended_to_path.feature +0 -140
  69. data/features/command_line/line_number_option.feature +0 -58
  70. data/features/command_line/order.feature +0 -25
  71. data/features/command_line/pattern_option.feature +0 -49
  72. data/features/command_line/rake_task.feature +0 -122
  73. data/features/command_line/randomization.feature +0 -63
  74. data/features/command_line/require_option.feature +0 -43
  75. data/features/command_line/ruby.feature +0 -23
  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 -39
  79. data/features/configuration/backtrace_exclusion_patterns.feature +0 -105
  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/enable_global_dsl.feature +0 -54
  84. data/features/configuration/fail_fast.feature +0 -77
  85. data/features/configuration/failure_exit_code.feature +0 -36
  86. data/features/configuration/order_and_seed.feature +0 -3
  87. data/features/configuration/output_stream.feature +0 -24
  88. data/features/configuration/overriding_global_ordering.feature +0 -93
  89. data/features/configuration/pattern.feature +0 -38
  90. data/features/configuration/profile.feature +0 -220
  91. data/features/configuration/read_options_from_file.feature +0 -90
  92. data/features/configuration/run_all_when_everything_filtered.feature +0 -76
  93. data/features/example_groups/aliasing.feature +0 -48
  94. data/features/example_groups/basic_structure.feature +0 -55
  95. data/features/example_groups/shared_context.feature +0 -74
  96. data/features/example_groups/shared_examples.feature +0 -286
  97. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
  98. data/features/filtering/exclusion_filters.feature +0 -135
  99. data/features/filtering/if_and_unless.feature +0 -138
  100. data/features/filtering/inclusion_filters.feature +0 -101
  101. data/features/formatters/configurable_colors.feature +0 -31
  102. data/features/formatters/custom_formatter.feature +0 -68
  103. data/features/formatters/json_formatter.feature +0 -30
  104. data/features/formatters/regression_tests.feature +0 -95
  105. data/features/formatters/text_formatter.feature +0 -46
  106. data/features/helper_methods/arbitrary_methods.feature +0 -40
  107. data/features/helper_methods/let.feature +0 -50
  108. data/features/helper_methods/modules.feature +0 -146
  109. data/features/hooks/around_hooks.feature +0 -344
  110. data/features/hooks/before_and_after_hooks.feature +0 -427
  111. data/features/hooks/filtering.feature +0 -232
  112. data/features/metadata/current_example.feature +0 -56
  113. data/features/metadata/described_class.feature +0 -17
  114. data/features/metadata/user_defined.feature +0 -100
  115. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  116. data/features/mock_framework_integration/use_flexmock.feature +0 -94
  117. data/features/mock_framework_integration/use_mocha.feature +0 -95
  118. data/features/mock_framework_integration/use_rr.feature +0 -96
  119. data/features/mock_framework_integration/use_rspec.feature +0 -95
  120. data/features/pending_and_skipped_examples/README.md +0 -3
  121. data/features/pending_and_skipped_examples/pending_examples.feature +0 -118
  122. data/features/pending_and_skipped_examples/skipped_examples.feature +0 -106
  123. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  124. data/features/step_definitions/additional_cli_steps.rb +0 -83
  125. data/features/subject/explicit_subject.feature +0 -101
  126. data/features/subject/implicit_subject.feature +0 -63
  127. data/features/subject/one_liner_syntax.feature +0 -71
  128. data/features/support/env.rb +0 -21
  129. data/features/support/require_expect_syntax_in_aruba_specs.rb +0 -16
  130. data/features/support/rubinius.rb +0 -6
  131. data/lib/rspec/core/command_line.rb +0 -35
  132. data/lib/rspec/core/drb_command_line.rb +0 -26
  133. data/lib/rspec/core/drb_options.rb +0 -87
  134. data/lib/rspec/core/formatters/legacy_formatter.rb +0 -227
  135. data/lib/rspec/core/shared_example_group/collection.rb +0 -27
  136. data/spec/command_line/order_spec.rb +0 -211
  137. data/spec/rspec/core/backtrace_formatter_spec.rb +0 -230
  138. data/spec/rspec/core/command_line_spec.rb +0 -112
  139. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  140. data/spec/rspec/core/configuration_options_spec.rb +0 -409
  141. data/spec/rspec/core/configuration_spec.rb +0 -1479
  142. data/spec/rspec/core/drb_command_line_spec.rb +0 -102
  143. data/spec/rspec/core/drb_options_spec.rb +0 -193
  144. data/spec/rspec/core/dsl_spec.rb +0 -88
  145. data/spec/rspec/core/example_group_spec.rb +0 -1533
  146. data/spec/rspec/core/example_spec.rb +0 -642
  147. data/spec/rspec/core/filter_manager_spec.rb +0 -229
  148. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -64
  149. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -303
  150. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -208
  151. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -75
  152. data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
  153. data/spec/rspec/core/formatters/html_formatted-2.1.0.html +0 -392
  154. data/spec/rspec/core/formatters/html_formatted.html +0 -397
  155. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -122
  156. data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -206
  157. data/spec/rspec/core/formatters/legacy_formatter_spec.rb +0 -137
  158. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -43
  159. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
  160. data/spec/rspec/core/formatters_spec.rb +0 -120
  161. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  162. data/spec/rspec/core/hooks_spec.rb +0 -294
  163. data/spec/rspec/core/memoized_helpers_spec.rb +0 -495
  164. data/spec/rspec/core/metadata_spec.rb +0 -491
  165. data/spec/rspec/core/option_parser_spec.rb +0 -262
  166. data/spec/rspec/core/ordering_spec.rb +0 -102
  167. data/spec/rspec/core/pending_example_spec.rb +0 -117
  168. data/spec/rspec/core/pending_spec.rb +0 -8
  169. data/spec/rspec/core/project_initializer_spec.rb +0 -73
  170. data/spec/rspec/core/rake_task_spec.rb +0 -146
  171. data/spec/rspec/core/random_spec.rb +0 -47
  172. data/spec/rspec/core/reporter_spec.rb +0 -155
  173. data/spec/rspec/core/resources/a_bar.rb +0 -0
  174. data/spec/rspec/core/resources/a_foo.rb +0 -0
  175. data/spec/rspec/core/resources/a_spec.rb +0 -1
  176. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  177. data/spec/rspec/core/resources/formatter_specs.rb +0 -58
  178. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  179. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  180. data/spec/rspec/core/ruby_project_spec.rb +0 -26
  181. data/spec/rspec/core/runner_spec.rb +0 -151
  182. data/spec/rspec/core/shared_context_spec.rb +0 -102
  183. data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -57
  184. data/spec/rspec/core/shared_example_group_spec.rb +0 -114
  185. data/spec/rspec/core/warnings_spec.rb +0 -29
  186. data/spec/rspec/core/world_spec.rb +0 -142
  187. data/spec/rspec/core_spec.rb +0 -91
  188. data/spec/spec_helper.rb +0 -160
  189. data/spec/support/config_options_helper.rb +0 -13
  190. data/spec/support/formatter_support.rb +0 -83
  191. data/spec/support/helper_methods.rb +0 -26
  192. data/spec/support/isolate_load_path_mutation.rb +0 -5
  193. data/spec/support/isolated_directory.rb +0 -10
  194. data/spec/support/isolated_home_directory.rb +0 -16
  195. data/spec/support/legacy_formatter_using_sub_classing_example.rb +0 -87
  196. data/spec/support/matchers.rb +0 -85
  197. data/spec/support/mathn_integration_support.rb +0 -12
  198. data/spec/support/old_style_formatter_example.rb +0 -69
  199. data/spec/support/shared_example_groups.rb +0 -13
  200. data/spec/support/spec_files.rb +0 -44
  201. data/spec/support/stderr_splitter.rb +0 -36
@@ -1,8 +1,9 @@
1
- require 'rspec/core/formatters/base_text_formatter'
1
+ RSpec::Support.require_rspec_core "formatters/base_text_formatter"
2
2
 
3
3
  module RSpec
4
4
  module Core
5
5
  module Formatters
6
+ # @private
6
7
  class DocumentationFormatter < BaseTextFormatter
7
8
  Formatters.register self, :example_group_started, :example_group_finished,
8
9
  :example_passed, :example_pending, :example_failed
@@ -13,8 +14,6 @@ module RSpec
13
14
  end
14
15
 
15
16
  def example_group_started(notification)
16
- super
17
-
18
17
  output.puts if @group_level == 0
19
18
  output.puts "#{current_indentation}#{notification.group.description.strip}"
20
19
 
@@ -30,27 +29,25 @@ module RSpec
30
29
  end
31
30
 
32
31
  def example_pending(pending)
33
- super
34
- output.puts pending_output(pending.example, pending.example.execution_result[:pending_message])
32
+ output.puts pending_output(pending.example, pending.example.execution_result.pending_message)
35
33
  end
36
34
 
37
35
  def example_failed(failure)
38
- super
39
- output.puts failure_output(failure.example, failure.example.execution_result[:exception])
36
+ output.puts failure_output(failure.example, failure.example.execution_result.exception)
40
37
  end
41
38
 
42
39
  private
43
40
 
44
41
  def passed_output(example)
45
- success_color("#{current_indentation}#{example.description.strip}")
42
+ ConsoleCodes.wrap("#{current_indentation}#{example.description.strip}", :success)
46
43
  end
47
44
 
48
45
  def pending_output(example, message)
49
- pending_color("#{current_indentation}#{example.description.strip} (PENDING: #{message})")
46
+ ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (PENDING: #{message})", :pending)
50
47
  end
51
48
 
52
49
  def failure_output(example, exception)
53
- failure_color("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})")
50
+ ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})", :failure)
54
51
  end
55
52
 
56
53
  def next_failure_index
@@ -1,21 +1,26 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Formatters
4
+ # Formatters helpers
4
5
  module Helpers
6
+
7
+ # @private
5
8
  SUB_SECOND_PRECISION = 5
9
+
10
+ # @private
6
11
  DEFAULT_PRECISION = 2
7
12
 
8
13
  # @api private
9
14
  #
10
15
  # Formats seconds into a human-readable string.
11
16
  #
12
- # @param [Float, Fixnum] duration in seconds
17
+ # @param duration [Float, Fixnum] in seconds
13
18
  # @return [String] human-readable time
14
19
  #
15
20
  # @example
16
21
  # format_duration(1) #=> "1 minute 1 second"
17
22
  # format_duration(135.14) #=> "2 minutes 15.14 seconds"
18
- def format_duration(duration)
23
+ def self.format_duration(duration)
19
24
  precision = case
20
25
  when duration < 1; SUB_SECOND_PRECISION
21
26
  when duration < 120; DEFAULT_PRECISION
@@ -38,7 +43,7 @@ module RSpec
38
43
  # Formats seconds to have 5 digits of precision with trailing zeros removed if the number
39
44
  # is less than 1 or with 2 digits of precision if the number is greater than zero.
40
45
  #
41
- # @param [Float] float
46
+ # @param float [Float]
42
47
  # @return [String] formatted float
43
48
  #
44
49
  # @example
@@ -49,7 +54,7 @@ module RSpec
49
54
  # The precision used is set in {Helpers::SUB_SECOND_PRECISION} and {Helpers::DEFAULT_PRECISION}.
50
55
  #
51
56
  # @see #strip_trailing_zeroes
52
- def format_seconds(float, precision = nil)
57
+ def self.format_seconds(float, precision = nil)
53
58
  precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
54
59
  formatted = sprintf("%.#{precision}f", float)
55
60
  strip_trailing_zeroes(formatted)
@@ -59,21 +64,22 @@ module RSpec
59
64
  #
60
65
  # Remove trailing zeros from a string.
61
66
  #
62
- # @param [String] string string with trailing zeros
67
+ # @param string [String] string with trailing zeros
63
68
  # @return [String] string with trailing zeros removed
64
- def strip_trailing_zeroes(string)
69
+ def self.strip_trailing_zeroes(string)
65
70
  stripped = string.sub(/[^1-9]+$/, '')
66
71
  stripped.empty? ? "0" : stripped
67
72
  end
73
+ private_class_method :strip_trailing_zeroes
68
74
 
69
75
  # @api private
70
76
  #
71
77
  # Pluralize a word based on a count.
72
78
  #
73
- # @param [Fixnum] count number of objects
74
- # @param [String] string word to be pluralized
79
+ # @param count [Fixnum] number of objects
80
+ # @param string [String] word to be pluralized
75
81
  # @return [String] pluralized word
76
- def pluralize(count, string)
82
+ def self.pluralize(count, string)
77
83
  "#{count} #{string}#{'s' unless count.to_f == 1}"
78
84
  end
79
85
  end
@@ -1,9 +1,10 @@
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
+ # @private
7
8
  class HtmlFormatter < BaseFormatter
8
9
  Formatters.register self, :start, :example_group_started, :start_dump,
9
10
  :example_started, :example_passed, :example_failed,
@@ -11,6 +12,7 @@ module RSpec
11
12
 
12
13
  def initialize(output)
13
14
  super(output)
15
+ @failed_examples = []
14
16
  @example_group_number = 0
15
17
  @example_number = 0
16
18
  @header_red = nil
@@ -46,13 +48,12 @@ module RSpec
46
48
 
47
49
  def example_passed(passed)
48
50
  @printer.move_progress(percent_done)
49
- @printer.print_example_passed( passed.example.description, passed.example.execution_result[:run_time] )
51
+ @printer.print_example_passed( passed.example.description, passed.example.execution_result.run_time )
50
52
  @printer.flush
51
53
  end
52
54
 
53
- def example_failed(failed)
54
- super
55
-
55
+ def example_failed(failure)
56
+ @failed_examples << failure.example
56
57
  unless @header_red
57
58
  @header_red = true
58
59
  @printer.make_header_red
@@ -65,23 +66,23 @@ module RSpec
65
66
 
66
67
  @printer.move_progress(percent_done)
67
68
 
68
- example = failed.example
69
+ example = failure.example
69
70
 
70
- exception = example.metadata[:execution_result][:exception]
71
+ exception = failure.exception
71
72
  exception_details = if exception
72
73
  {
73
74
  :message => exception.message,
74
- :backtrace => format_backtrace(exception.backtrace, example).join("\n")
75
+ :backtrace => failure.formatted_backtrace.join("\n")
75
76
  }
76
77
  else
77
78
  false
78
79
  end
79
- extra = extra_failure_content(exception)
80
+ extra = extra_failure_content(failure)
80
81
 
81
82
  @printer.print_example_failed(
82
- example.execution_result[:pending_fixed],
83
+ example.execution_result.pending_fixed,
83
84
  example.description,
84
- example.execution_result[:run_time],
85
+ example.execution_result.run_time,
85
86
  @failed_examples.size,
86
87
  exception_details,
87
88
  (extra == "") ? false : extra,
@@ -96,7 +97,7 @@ module RSpec
96
97
  @printer.make_header_yellow unless @header_red
97
98
  @printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
98
99
  @printer.move_progress(percent_done)
99
- @printer.print_example_pending( example.description, example.metadata[:execution_result][:pending_message] )
100
+ @printer.print_example_pending( example.description, example.execution_result.pending_message )
100
101
  @printer.flush
101
102
  end
102
103
 
@@ -133,9 +134,9 @@ module RSpec
133
134
  # Override this method if you wish to output extra HTML for a failed spec. For example, you
134
135
  # could output links to images or other files produced during the specs.
135
136
  #
136
- def extra_failure_content(exception)
137
- require 'rspec/core/formatters/snippet_extractor'
138
- backtrace = exception.backtrace.map {|line| configuration.backtrace_formatter.backtrace_line(line)}
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)}
139
140
  backtrace.compact!
140
141
  @snippet_extractor ||= SnippetExtractor.new
141
142
  " <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
@@ -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)
@@ -1,12 +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
+ # @private
7
8
  class JsonFormatter < BaseFormatter
8
- Formatters.register self, :message, :dump_summary, :stop, :close,
9
- :dump_profile
9
+ Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :close
10
10
 
11
11
  attr_reader :output_hash
12
12
 
@@ -26,13 +26,11 @@ module RSpec
26
26
  :failure_count => summary.failure_count,
27
27
  :pending_count => summary.pending_count
28
28
  }
29
- @output_hash[:summary_line] = summary.summary_line
30
-
31
- dump_profile unless mute_profile_output?(summary.failure_count)
29
+ @output_hash[:summary_line] = summary.totals_line
32
30
  end
33
31
 
34
32
  def stop(notification)
35
- @output_hash[:examples] = examples.map do |example|
33
+ @output_hash[:examples] = notification.examples.map do |example|
36
34
  format_example(example).tap do |hash|
37
35
  if e=example.exception
38
36
  hash[:exception] = {
@@ -50,29 +48,29 @@ module RSpec
50
48
  output.close if IO === output && output != $stdout
51
49
  end
52
50
 
53
- def dump_profile
51
+ def dump_profile(profile)
54
52
  @output_hash[:profile] = {}
55
- dump_profile_slowest_examples
56
- dump_profile_slowest_example_groups
53
+ dump_profile_slowest_examples(profile)
54
+ dump_profile_slowest_example_groups(profile)
57
55
  end
58
56
 
59
57
  # @api private
60
- def dump_profile_slowest_examples
58
+ def dump_profile_slowest_examples(profile)
61
59
  @output_hash[:profile] = {}
62
- sorted_examples = slowest_examples
63
- @output_hash[:profile][:examples] = sorted_examples[:examples].map do |example|
60
+ sorted_examples = profile.slowest_examples
61
+ @output_hash[:profile][:examples] = sorted_examples.map do |example|
64
62
  format_example(example).tap do |hash|
65
- hash[:run_time] = example.execution_result[:run_time]
63
+ hash[:run_time] = example.execution_result.run_time
66
64
  end
67
65
  end
68
- @output_hash[:profile][:slowest] = sorted_examples[:slows]
69
- @output_hash[:profile][:total] = sorted_examples[:total]
66
+ @output_hash[:profile][:slowest] = profile.slow_duration
67
+ @output_hash[:profile][:total] = profile.duration
70
68
  end
71
69
 
72
70
  # @api private
73
- def dump_profile_slowest_example_groups
71
+ def dump_profile_slowest_example_groups(profile)
74
72
  @output_hash[:profile] ||= {}
75
- @output_hash[:profile][:groups] = slowest_groups.map do |loc, hash|
73
+ @output_hash[:profile][:groups] = profile.slowest_groups.map do |loc, hash|
76
74
  hash.update(:location => loc)
77
75
  end
78
76
  end
@@ -83,10 +81,10 @@ module RSpec
83
81
  {
84
82
  :description => example.description,
85
83
  :full_description => example.full_description,
86
- :status => example.execution_result[:status],
84
+ :status => example.execution_result.status.to_s,
87
85
  :file_path => example.metadata[:file_path],
88
86
  :line_number => example.metadata[:line_number],
89
- :run_time => example.execution_result[:run_time]
87
+ :run_time => example.execution_result.run_time
90
88
  }
91
89
  end
92
90
  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,28 +1,27 @@
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
6
+ # @private
5
7
  class ProgressFormatter < BaseTextFormatter
6
8
  Formatters.register self, :example_passed, :example_pending, :example_failed, :start_dump
7
9
 
8
10
  def example_passed(notification)
9
- output.print success_color('.')
11
+ output.print ConsoleCodes.wrap('.', :success)
10
12
  end
11
13
 
12
14
  def example_pending(notification)
13
- super
14
- output.print pending_color('*')
15
+ output.print ConsoleCodes.wrap('*', :pending)
15
16
  end
16
17
 
17
18
  def example_failed(notification)
18
- super
19
- output.print failure_color('F')
19
+ output.print ConsoleCodes.wrap('F', :failure)
20
20
  end
21
21
 
22
22
  def start_dump(notification)
23
23
  output.puts
24
24
  end
25
-
26
25
  end
27
26
  end
28
27
  end
@@ -5,12 +5,14 @@ module RSpec
5
5
  #
6
6
  # Extracts code snippets by looking at the backtrace of the passed error and applies synax highlighting and line numbers using html.
7
7
  class SnippetExtractor
8
+ # @private
8
9
  class NullConverter
9
10
  def convert(code)
10
11
  %Q(#{code}\n<span class="comment"># Install the coderay gem to get syntax highlighting</span>)
11
12
  end
12
13
  end
13
14
 
15
+ # @private
14
16
  class CoderayConverter
15
17
  def convert(code)
16
18
  CodeRay.scan(code, :ruby).html(:line_numbers => false)
@@ -28,7 +30,7 @@ module RSpec
28
30
  #
29
31
  # Extract lines of code corresponding to a backtrace.
30
32
  #
31
- # @param [String] backtrace the backtrace from a test failure
33
+ # @param backtrace [String] the backtrace from a test failure
32
34
  # @return [String] highlighted code snippet indicating where the test failure occured
33
35
  #
34
36
  # @see #post_process
@@ -42,7 +44,7 @@ module RSpec
42
44
  #
43
45
  # Create a snippet from a line of code.
44
46
  #
45
- # @param [String] error_line file name with line number (i.e. 'foo_spec.rb:12')
47
+ # @param error_line [String] file name with line number (i.e. 'foo_spec.rb:12')
46
48
  # @return [String] lines around the target line within the file
47
49
  #
48
50
  # @see #lines_around
@@ -60,8 +62,8 @@ module RSpec
60
62
  #
61
63
  # Extract lines of code centered around a particular line within a source file.
62
64
  #
63
- # @param [String] file filename
64
- # @param [Fixnum] line line number
65
+ # @param file [String] filename
66
+ # @param line [Fixnum] line number
65
67
  # @return [String] lines around the target line within the file (2 above and 1 below).
66
68
  def lines_around(file, line)
67
69
  if File.file?(file)
@@ -82,8 +84,8 @@ module RSpec
82
84
  #
83
85
  # Adds line numbers to all lines and highlights the line where the failure occurred using html `span` tags.
84
86
  #
85
- # @param [String] highlighted syntax-highlighted snippet surrounding the offending line of code
86
- # @param [Fixnum] offending_line line where failure occured
87
+ # @param highlighted [String] syntax-highlighted snippet surrounding the offending line of code
88
+ # @param offending_line [Fixnum] line where failure occured
87
89
  # @return [String] completed snippet
88
90
  def post_process(highlighted, offending_line)
89
91
  new_lines = []