rspec-core 3.0.0.beta2 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -2,7 +2,7 @@
2
2
  require 'optparse'
3
3
 
4
4
  module RSpec::Core
5
- # @api private
5
+ # @private
6
6
  class Parser
7
7
  def self.parse(args)
8
8
  new.parse(args)
@@ -11,8 +11,6 @@ module RSpec::Core
11
11
  def parse(args)
12
12
  return {} if args.empty?
13
13
 
14
- convert_deprecated_args(args)
15
-
16
14
  options = args.delete('--tty') ? {:tty => true} : {}
17
15
  begin
18
16
  parser(options).parse!(args)
@@ -23,19 +21,6 @@ module RSpec::Core
23
21
  options
24
22
  end
25
23
 
26
- def convert_deprecated_args(args)
27
- args.map! { |arg|
28
- case arg
29
- when "--default_path"
30
- "--default-path"
31
- when "--line_number"
32
- "--line-number"
33
- else
34
- arg
35
- end
36
- }
37
- end
38
-
39
24
  def parser(options)
40
25
  OptionParser.new do |parser|
41
26
  parser.banner = "Usage: rspec [options] [files or directories]\n\n"
@@ -92,7 +77,7 @@ module RSpec::Core
92
77
  end
93
78
 
94
79
  parser.on('--init', 'Initialize your project with RSpec.') do |cmd|
95
- require 'rspec/core/project_initializer'
80
+ RSpec::Support.require_rspec_core "project_initializer"
96
81
  ProjectInitializer.new.run
97
82
  exit
98
83
  end
@@ -118,6 +103,10 @@ module RSpec::Core
118
103
  options[:formatters].last << o
119
104
  end
120
105
 
106
+ parser.on('--deprecation-out FILE', 'Write deprecation warnings to a file instead of $stderr.') do |file|
107
+ options[:deprecation_stream] = file
108
+ end
109
+
121
110
  parser.on('-b', '--backtrace', 'Enable full backtrace.') do |o|
122
111
  options[:full_backtrace] = true
123
112
  end
@@ -145,7 +134,7 @@ module RSpec::Core
145
134
  end
146
135
 
147
136
  parser.on('-w', '--warnings', 'Enable ruby warnings') do
148
- options[:warnings] = true
137
+ $VERBOSE = true
149
138
  end
150
139
 
151
140
  parser.separator <<-FILTERING
@@ -169,11 +158,6 @@ FILTERING
169
158
  (options[:full_description] ||= []) << Regexp.compile(Regexp.escape(o))
170
159
  end
171
160
 
172
- parser.on('-l', '--line-number LINE', 'Specify line number of an example or group (may be',
173
- ' used more than once).') do |o|
174
- (options[:line_numbers] ||= []) << o
175
- end
176
-
177
161
  parser.on('-t', '--tag TAG[:VALUE]',
178
162
  'Run examples with the specified tag, or exclude examples',
179
163
  'by adding ~ before the tag.',
@@ -210,12 +194,19 @@ FILTERING
210
194
  exit
211
195
  end
212
196
 
197
+ # these options would otherwise be confusing to users, so we forcibly prevent them from executing
198
+ # --I is too similar to -I
199
+ # -d was a shorthand for --debugger, which is removed, but now would trigger --default-path
200
+ invalid_options = %w[-d --I]
201
+
213
202
  parser.on_tail('-h', '--help', "You're looking at it.") do
214
- puts parser
203
+ # removing the blank invalid options from the output
204
+ puts parser.to_s.gsub(/^\s+(#{invalid_options.join('|')})\s*$\n/,'')
215
205
  exit
216
206
  end
217
207
 
218
- %w[-d --I].each do |option|
208
+ # this prevents usage of the invalid_options
209
+ invalid_options.each do |option|
219
210
  parser.on(option) do
220
211
  raise OptionParser::InvalidOption.new
221
212
  end
@@ -1,9 +1,11 @@
1
1
  module RSpec
2
2
  module Core
3
3
  if defined?(::Random)
4
+ # @private
4
5
  RandomNumberGenerator = ::Random
5
6
  else
6
- require 'rspec/core/backport_random'
7
+ RSpec::Support.require_rspec_core "backport_random"
8
+ # @private
7
9
  RandomNumberGenerator = RSpec::Core::Backports::Random
8
10
  end
9
11
 
@@ -1,6 +1,9 @@
1
1
  module RSpec
2
2
  module Core
3
+ # Provides methods to mark examples as pending. These methods are available to be
4
+ # called from within any example or hook.
3
5
  module Pending
6
+ # Raised in the middle of an example to indicate that it should be marked as skipped.
4
7
  class SkipDeclaredInExample < StandardError
5
8
  attr_reader :argument
6
9
 
@@ -9,7 +12,7 @@ module RSpec
9
12
  end
10
13
  end
11
14
 
12
- # If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit
15
+ # If Test::Unit is loaded, we'll use its error as baseclass, so that Test::Unit
13
16
  # will report unmet RSpec expectations as failures rather than errors.
14
17
  begin
15
18
  class PendingExampleFixedError < Test::Unit::AssertionFailedError; end
@@ -17,26 +20,27 @@ module RSpec
17
20
  class PendingExampleFixedError < StandardError; end
18
21
  end
19
22
 
23
+ # @private
20
24
  NO_REASON_GIVEN = 'No reason given'
25
+
26
+ # @private
21
27
  NOT_YET_IMPLEMENTED = 'Not yet implemented'
22
28
 
23
29
  # @overload pending()
24
30
  # @overload pending(message)
25
- # @overload pending(message, &block)
26
31
  #
27
32
  # Marks an example as pending. The rest of the example will still be
28
33
  # executed, and if it passes the example will fail to indicate that the
29
34
  # pending can be removed.
30
35
  #
31
- # @param [String] message optional message to add to the summary report.
36
+ # @param message [String] optional message to add to the summary report.
32
37
  #
33
38
  # @example
34
- #
35
39
  # describe "an example" do
36
40
  # # reported as "Pending: no reason given"
37
41
  # it "is pending with no message" do
38
42
  # pending
39
- # raise "broken"
43
+ # raise "broken"
40
44
  # end
41
45
  #
42
46
  # # reported as "Pending: something else getting finished"
@@ -46,7 +50,7 @@ module RSpec
46
50
  # end
47
51
  # end
48
52
  #
49
- # @note `before(:each)` hooks are eval'd when you use the `pending`
53
+ # @note `before(:example)` hooks are eval'd when you use the `pending`
50
54
  # method within an example. If you want to declare an example `pending`
51
55
  # and bypass the `before` hooks as well, you can pass `:pending => true`
52
56
  # to the `it` method:
@@ -61,32 +65,43 @@ module RSpec
61
65
  # it "does something", :pending => "something else getting finished" do
62
66
  # # ...
63
67
  # end
64
- def pending(*args)
68
+ def pending(message=nil)
65
69
  current_example = RSpec.current_example
66
70
 
67
- if current_example
68
- Pending.mark_pending! current_example, args.first
71
+ if block_given?
72
+ raise ArgumentError, <<-EOS.gsub(/^\s+\|/, '')
73
+ |The semantics of `RSpec::Core::Pending#pending` have changed in
74
+ |RSpec 3. In RSpec 2.x, it caused the example to be skipped. In
75
+ |RSpec 3, the rest of the example is still run but is expected to
76
+ |fail, and will be marked as a failure (rather than as pending) if
77
+ |the example passes.
78
+ |
79
+ |Passing a block within an example is now deprecated. Marking the
80
+ |example as pending provides the same behavior in RSpec 3 which was
81
+ |provided only by the block in RSpec 2.x.
82
+ |
83
+ |Move the code in the block provided to `pending` into the rest of
84
+ |the example body.
85
+ |
86
+ |Called from #{CallerFilter.first_non_rspec_line}.
87
+ |
88
+ EOS
89
+ elsif current_example
90
+ Pending.mark_pending! current_example, message
69
91
  else
70
92
  raise "`pending` may not be used outside of examples, such as in " +
71
- "before(:all). Maybe you want `skip`?"
93
+ "before(:context). Maybe you want `skip`?"
72
94
  end
73
95
  end
74
96
 
75
97
  # @overload skip()
76
98
  # @overload skip(message)
77
- # @overload skip(message, &block)
78
99
  #
79
- # Marks an example as pending and skips execution when called without a
80
- # block. When called with a block, skips just that block and does not
81
- # mark the example as pending. The block form is provided as replacement
82
- # for RSpec 2's pending-with-block feature, and is not recommended for
83
- # new code. Use simple conditionals instead.
100
+ # Marks an example as pending and skips execution.
84
101
  #
85
- # @param [String] message optional message to add to the summary report.
86
- # @block [Block] block optional block to be skipped
102
+ # @param message [String] optional message to add to the summary report.
87
103
  #
88
104
  # @example
89
- #
90
105
  # describe "an example" do
91
106
  # # reported as "Pending: no reason given"
92
107
  # it "is skipped with no message" do
@@ -97,29 +112,34 @@ module RSpec
97
112
  # it "is skipped with a custom message" do
98
113
  # skip "something else getting finished"
99
114
  # end
100
- #
101
- # # Passes
102
- # it "contains a skipped statement" do
103
- # skip do
104
- # fail
105
- # end
106
- # end
107
115
  # end
108
- def skip(*args)
116
+ def skip(message=nil)
109
117
  current_example = RSpec.current_example
110
118
 
111
119
  if current_example
112
- Pending.mark_skipped! current_example, args.first
120
+ Pending.mark_skipped! current_example, message
113
121
  end
114
122
 
115
- raise SkipDeclaredInExample.new(args.first)
123
+ raise SkipDeclaredInExample.new(message)
116
124
  end
117
125
 
126
+ # @private
127
+ #
128
+ # Mark example as skipped
129
+ #
130
+ # @param example [RSpec::Core::Example] the example to mark as skipped
131
+ # @param message_or_bool [Boolean, String] the message to use, or true
118
132
  def self.mark_skipped!(example, message_or_bool)
119
133
  Pending.mark_pending! example, message_or_bool
120
134
  example.metadata[:skip] = true
121
135
  end
122
136
 
137
+ # @private
138
+ #
139
+ # Mark example as pending
140
+ #
141
+ # @param example [RSpec::Core::Example] the example to mark as pending
142
+ # @param message_or_bool [Boolean, String] the message to use, or true
123
143
  def self.mark_pending!(example, message_or_bool)
124
144
  message = if !message_or_bool || !(String === message_or_bool)
125
145
  NO_REASON_GIVEN
@@ -128,13 +148,17 @@ module RSpec
128
148
  end
129
149
 
130
150
  example.metadata[:pending] = true
131
- example.metadata[:execution_result][:pending_message] = message
132
- example.execution_result[:pending_fixed] = false
151
+ example.execution_result.pending_message = message
152
+ example.execution_result.pending_fixed = false
133
153
  end
134
154
 
155
+ # @private
156
+ #
157
+ # Mark example as fixed
158
+ #
159
+ # @param example [RSpec::Core::Example] the example to mark as fixed
135
160
  def self.mark_fixed!(example)
136
- example.metadata[:pending] = false
137
- example.metadata[:execution_result][:pending_fixed] = true
161
+ example.execution_result.pending_fixed = true
138
162
  end
139
163
  end
140
164
  end
@@ -1,5 +1,7 @@
1
1
  module RSpec
2
2
  module Core
3
+ # @private
4
+ # Generates conventional files for an rspec project
3
5
  class ProjectInitializer
4
6
  def run
5
7
  create_spec_helper_file
@@ -5,9 +5,10 @@
5
5
  #
6
6
  # Given that it is always loaded, you are encouraged to keep this file as
7
7
  # light-weight as possible. Requiring heavyweight dependencies from this file
8
- # (such as loading up an entire rails app) will add to the boot time of your
9
- # test suite on EVERY test run, even for an individual file that may not need
10
- # all of that loaded.
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
11
12
  #
12
13
  # The `.rspec` file also contains a few flags that are not defaults but that
13
14
  # users commonly want.
@@ -36,7 +37,7 @@ RSpec.configure do |config|
36
37
  # Use the documentation formatter for detailed output,
37
38
  # unless a formatter has already been configured
38
39
  # (e.g. via a command-line flag).
39
- config.formatter = 'doc' if config.formatters.none?
40
+ config.default_formatter = 'doc'
40
41
  end
41
42
 
42
43
  # Print the 10 slowest examples and example groups at the
@@ -1,13 +1,25 @@
1
- require 'rspec/support/warnings'
1
+ require 'rspec/support'
2
+ require 'rspec/core/version'
3
+ RSpec::Support.require_rspec_support "warnings"
4
+
2
5
  require 'rake'
3
6
  require 'rake/tasklib'
4
7
  require 'shellwords'
5
8
 
6
9
  module RSpec
7
10
  module Core
11
+ # Rspec rake task
12
+ #
13
+ # @see Rakefile
8
14
  class RakeTask < ::Rake::TaskLib
9
15
  include ::Rake::DSL if defined?(::Rake::DSL)
10
16
 
17
+ # Default path to the rspec executable
18
+ DEFAULT_RSPEC_PATH = File.expand_path('../../../../exe/rspec', __FILE__)
19
+
20
+ # Default pattern for spec files.
21
+ DEFAULT_PATTERN = './spec{,/*/**}/*_spec.rb'
22
+
11
23
  # Name of task.
12
24
  #
13
25
  # default:
@@ -55,27 +67,18 @@ module RSpec
55
67
  attr_accessor :rspec_opts
56
68
 
57
69
  def initialize(*args, &task_block)
58
- setup_ivars(args)
59
-
60
- desc "Run RSpec code examples" unless ::Rake.application.last_comment
61
-
62
- task name, *args do |_, task_args|
63
- RakeFileUtils.__send__(:verbose, verbose) do
64
- task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
65
- run_task verbose
66
- end
67
- end
68
- end
69
-
70
- def setup_ivars(args)
71
- @name = args.shift || :spec
72
- @ruby_opts, @rspec_opts = nil, nil, nil
73
- @verbose, @fail_on_error = true, true
74
-
75
- @rspec_path = 'rspec'
76
- @pattern = './spec{,/*/**}/*_spec.rb'
70
+ @name = args.shift || :spec
71
+ @ruby_opts = nil
72
+ @rspec_opts = nil
73
+ @verbose = true
74
+ @fail_on_error = true
75
+ @rspec_path = DEFAULT_RSPEC_PATH
76
+ @pattern = DEFAULT_PATTERN
77
+
78
+ define(args, &task_block)
77
79
  end
78
80
 
81
+ # @private
79
82
  def run_task(verbose)
80
83
  command = spec_command
81
84
 
@@ -93,6 +96,18 @@ module RSpec
93
96
 
94
97
  private
95
98
 
99
+ # @private
100
+ def define(args, &task_block)
101
+ desc "Run RSpec code examples" unless ::Rake.application.last_comment
102
+
103
+ task name, *args do |_, task_args|
104
+ RakeFileUtils.__send__(:verbose, verbose) do
105
+ task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
106
+ run_task verbose
107
+ end
108
+ end
109
+ end
110
+
96
111
  def files_to_run
97
112
  if ENV['SPEC']
98
113
  FileList[ ENV['SPEC'] ].sort
@@ -105,6 +120,7 @@ module RSpec
105
120
  cmd_parts = []
106
121
  cmd_parts << RUBY
107
122
  cmd_parts << ruby_opts
123
+ cmd_parts << rspec_load_path
108
124
  cmd_parts << "-S" << rspec_path
109
125
  cmd_parts << files_to_run
110
126
  cmd_parts << rspec_opts
@@ -114,6 +130,15 @@ module RSpec
114
130
  def blank
115
131
  lambda {|s| s.nil? || s == ""}
116
132
  end
133
+
134
+ def rspec_load_path
135
+ @rspec_load_path ||= begin
136
+ core_and_support = $LOAD_PATH.grep \
137
+ %r{#{File::SEPARATOR}rspec-(core|support)[^#{File::SEPARATOR}]*#{File::SEPARATOR}lib}
138
+
139
+ "-I#{core_and_support.map(&:shellescape).join(File::PATH_SEPARATOR)}"
140
+ end
141
+ end
117
142
  end
118
143
  end
119
144
  end
@@ -1,19 +1,25 @@
1
1
  module RSpec::Core
2
+ # A reporter will send notifications to listeners, usually formatters for the
3
+ # spec suite run.
2
4
  class Reporter
3
5
 
4
6
  def initialize(configuration)
5
7
  @configuration = configuration
6
8
  @listeners = Hash.new { |h,k| h[k] = Set.new }
7
- @example_count = @failure_count = @pending_count = 0
8
- @duration = @start = nil
9
+ @examples = []
10
+ @failed_examples = []
11
+ @pending_examples = []
12
+ @duration = @start = @load_time = nil
9
13
  end
10
14
 
11
- # @api
12
- # @param [Object] An obect that wishes to be notified of reporter events
13
- # @param [Array] Array of symbols represents the events a listener wishes to subscribe too
14
- #
15
+ # @private
16
+ attr_reader :examples, :failed_examples, :pending_examples
17
+
15
18
  # Registers a listener to a list of notifications. The reporter will send notification of
16
19
  # events to all registered listeners
20
+ #
21
+ # @param listener [Object] An obect that wishes to be notified of reporter events
22
+ # @param notifications [Array] Array of symbols represents the events a listener wishes to subscribe too
17
23
  def register_listener(listener, *notifications)
18
24
  notifications.each do |notification|
19
25
  @listeners[notification.to_sym] << listener
@@ -21,6 +27,7 @@ module RSpec::Core
21
27
  true
22
28
  end
23
29
 
30
+ # @private
24
31
  def registered_listeners(notification)
25
32
  @listeners[notification].to_a
26
33
  end
@@ -28,8 +35,8 @@ module RSpec::Core
28
35
  # @api
29
36
  # @overload report(count, &block)
30
37
  # @overload report(count, &block)
31
- # @param [Integer] count the number of examples being run
32
- # @param [Block] block yields itself for further reporting.
38
+ # @param expected_example_count [Integer] the number of examples being run
39
+ # @yield [Block] block yields itself for further reporting.
33
40
  #
34
41
  # Initializes the report run and yields itself for further reporting. The
35
42
  # block is required, so that the reporter can manage cleaning up after the
@@ -50,65 +57,81 @@ module RSpec::Core
50
57
  end
51
58
  end
52
59
 
53
- def start(expected_example_count)
54
- @start = RSpec::Core::Time.now
55
- notify :start, Notifications::CountNotification.new(expected_example_count)
60
+ # @private
61
+ def start(expected_example_count, time = RSpec::Core::Time.now)
62
+ @start = time
63
+ @load_time = (@start - @configuration.start_time).to_f
64
+ notify :start, Notifications::StartNotification.new(expected_example_count, @load_time)
56
65
  end
57
66
 
67
+ # @private
58
68
  def message(message)
59
69
  notify :message, Notifications::MessageNotification.new(message)
60
70
  end
61
71
 
72
+ # @private
62
73
  def example_group_started(group)
63
74
  notify :example_group_started, Notifications::GroupNotification.new(group) unless group.descendant_filtered_examples.empty?
64
75
  end
65
76
 
77
+ # @private
66
78
  def example_group_finished(group)
67
79
  notify :example_group_finished, Notifications::GroupNotification.new(group) unless group.descendant_filtered_examples.empty?
68
80
  end
69
81
 
82
+ # @private
70
83
  def example_started(example)
71
- @example_count += 1
72
- notify :example_started, Notifications::ExampleNotification.new(example)
84
+ @examples << example
85
+ notify :example_started, Notifications::ExampleNotification.for(example)
73
86
  end
74
87
 
88
+ # @private
75
89
  def example_passed(example)
76
- notify :example_passed, Notifications::ExampleNotification.new(example)
90
+ notify :example_passed, Notifications::ExampleNotification.for(example)
77
91
  end
78
92
 
93
+ # @private
79
94
  def example_failed(example)
80
- @failure_count += 1
81
- notify :example_failed, Notifications::ExampleNotification.new(example)
95
+ @failed_examples << example
96
+ notify :example_failed, Notifications::ExampleNotification.for(example)
82
97
  end
83
98
 
99
+ # @private
84
100
  def example_pending(example)
85
- @pending_count += 1
86
- notify :example_pending, Notifications::ExampleNotification.new(example)
101
+ @pending_examples << example
102
+ notify :example_pending, Notifications::ExampleNotification.for(example)
87
103
  end
88
104
 
105
+ # @private
89
106
  def deprecation(hash)
90
107
  notify :deprecation, Notifications::DeprecationNotification.from_hash(hash)
91
108
  end
92
109
 
110
+ # @private
93
111
  def finish
94
112
  begin
95
113
  stop
96
114
  notify :start_dump, Notifications::NullNotification
97
- notify :dump_pending, Notifications::NullNotification
98
- notify :dump_failures, Notifications::NullNotification
99
- notify :dump_summary, Notifications::SummaryNotification.new(@duration, @example_count, @failure_count, @pending_count)
115
+ notify :dump_pending, Notifications::ExamplesNotification.new(self)
116
+ notify :dump_failures, Notifications::ExamplesNotification.new(self)
100
117
  notify :deprecation_summary, Notifications::NullNotification
118
+ notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples, @pending_examples, @load_time)
119
+ unless mute_profile_output?
120
+ notify :dump_profile, Notifications::ProfileNotification.new(@duration, @examples, @configuration.profile_examples)
121
+ end
101
122
  notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
102
123
  ensure
103
124
  notify :close, Notifications::NullNotification
104
125
  end
105
126
  end
106
127
 
128
+ # @private
107
129
  def stop
108
130
  @duration = (RSpec::Core::Time.now - @start).to_f if @start
109
- notify :stop, Notifications::NullNotification
131
+ notify :stop, Notifications::ExamplesNotification.new(self)
110
132
  end
111
133
 
134
+ # @private
112
135
  def notify(event, notification)
113
136
  registered_listeners(event).each do |formatter|
114
137
  formatter.__send__(event, notification)
@@ -117,6 +140,11 @@ module RSpec::Core
117
140
 
118
141
  private
119
142
 
143
+ def mute_profile_output?
144
+ # Don't print out profiled info if there are failures and `--fail-fast` is used, it just clutters the output
145
+ !@configuration.profile_examples? || (@configuration.fail_fast? && @failed_examples.size > 0)
146
+ end
147
+
120
148
  def seed_used?
121
149
  @configuration.seed && @configuration.seed_used?
122
150
  end