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
@@ -0,0 +1,78 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
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.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
@@ -1,86 +1,46 @@
1
1
  module RSpec
2
2
  module Core
3
+ # @private
4
+ # Generates conventional files for an rspec project
3
5
  class ProjectInitializer
4
- def initialize(arg=nil)
5
- @arg = arg
6
- end
6
+ attr_reader :destination, :stream, :template_path
7
7
 
8
- def run
9
- create_spec_helper_file
10
- create_dot_rspec_file
11
- delete_if_confirmed("autotest/discover.rb", <<-MESSAGE)
12
- RSpec registers its own discover.rb with Autotest, so autotest/discover.rb is
13
- no longer needed.
14
- MESSAGE
8
+ DOT_RSPEC_FILE = '.rspec'
9
+ SPEC_HELPER_FILE = 'spec/spec_helper.rb'
15
10
 
16
- delete_if_confirmed("lib/tasks/rspec.rake", <<-MESSAGE)
17
- If the file in lib/tasks/rspec.rake is the one generated by rspec-rails-1x,
18
- you can get rid of it, as it is no longer needed with rspec-2.
19
- MESSAGE
11
+ def initialize(opts = {})
12
+ @destination = opts.fetch(:destination, Dir.getwd)
13
+ @stream = opts.fetch(:report_stream, $stdout)
14
+ @template_path = opts.fetch(:template_path) do
15
+ File.expand_path("../project_initializer", __FILE__)
16
+ end
20
17
  end
21
18
 
22
- def create_dot_rspec_file
23
- if File.exist?('.rspec')
24
- report_exists('.rspec')
25
- else
26
- report_creating('.rspec')
27
- File.open('.rspec','w') do |f|
28
- f.write <<-CONTENT
29
- --color
30
- --format progress
31
- CONTENT
32
- end
33
- end
19
+ def run
20
+ copy_template DOT_RSPEC_FILE
21
+ copy_template SPEC_HELPER_FILE
34
22
  end
35
23
 
36
- def create_spec_helper_file
37
- if File.exist?('spec/spec_helper.rb')
38
- report_exists("spec/spec_helper.rb")
39
- else
40
- report_creating("spec/spec_helper.rb")
41
- FileUtils.mkdir_p('spec')
42
- File.open('spec/spec_helper.rb','w') do |f|
43
- f.write <<-CONTENT
44
- # This file was generated by the `rspec --init` command. Conventionally, all
45
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
46
- # Require this file using `require "spec_helper"` to ensure that it is only
47
- # loaded once.
48
- #
49
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
50
- RSpec.configure do |config|
51
- config.treat_symbols_as_metadata_keys_with_true_values = true
52
- config.run_all_when_everything_filtered = true
53
- config.filter_run :focus
24
+ private
54
25
 
55
- # Run specs in random order to surface order dependencies. If you find an
56
- # order dependency and want to debug it, you can fix the order by providing
57
- # the seed, which is printed after each run.
58
- # --seed 1234
59
- config.order = 'random'
60
- end
61
- CONTENT
62
- end
63
- end
64
- end
26
+ def copy_template(file)
27
+ destination_file = File.join(destination, file)
28
+ return report_exists(file) if File.exist?(destination_file)
65
29
 
66
- def delete_if_confirmed(path, message)
67
- if File.exist?(path)
68
- puts
69
- puts message
70
- puts
71
- puts " delete #{path}? [y/n]"
72
- FileUtils.rm_rf(path) if gets =~ /y/i
30
+ report_creating(file)
31
+ FileUtils.mkdir_p(File.dirname(destination_file))
32
+ File.open(destination_file, 'w') do |f|
33
+ f.write File.read(File.join(template_path, file))
73
34
  end
74
35
  end
75
36
 
76
37
  def report_exists(file)
77
- puts " exist #{file}"
38
+ stream.puts " exist #{file}"
78
39
  end
79
40
 
80
41
  def report_creating(file)
81
- puts " create #{file}"
42
+ stream.puts " create #{file}"
82
43
  end
83
-
84
44
  end
85
45
  end
86
46
  end
@@ -1,13 +1,25 @@
1
- require 'rspec/core/backward_compatibility'
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:
@@ -20,31 +32,6 @@ module RSpec
20
32
  # 'spec/**/*_spec.rb'
21
33
  attr_accessor :pattern
22
34
 
23
- # @deprecated
24
- # Has no effect. The rake task now checks ENV['BUNDLE_GEMFILE'] instead.
25
- def skip_bundler=(*)
26
- deprecate("RSpec::Core::RakeTask#skip_bundler=")
27
- end
28
-
29
- # @deprecated
30
- # Has no effect. The rake task now checks ENV['BUNDLE_GEMFILE'] instead.
31
- def gemfile=(*)
32
- deprecate("RSpec::Core::RakeTask#gemfile=", :replacement => 'ENV["BUNDLE_GEMFILE"]')
33
- end
34
-
35
- # @deprecated
36
- # Use ruby_opts="-w" instead.
37
- #
38
- # When true, requests that the specs be run with the warning flag set.
39
- # e.g. "ruby -w"
40
- #
41
- # default:
42
- # false
43
- def warning=(true_or_false)
44
- deprecate("RSpec::Core::RakeTask#warning=", :replacement => 'ruby_opts="-w"')
45
- @warning = true_or_false
46
- end
47
-
48
35
  # Whether or not to fail Rake when an error occurs (typically when examples fail).
49
36
  #
50
37
  # default:
@@ -61,51 +48,6 @@ module RSpec
61
48
  # true
62
49
  attr_accessor :verbose
63
50
 
64
- # Use rcov for code coverage?
65
- #
66
- # Due to the many ways `rcov` can run, if this option is enabled, it is
67
- # required that `require 'rspec/autorun'` appears in `spec_helper`.rb
68
- #
69
- # default:
70
- # false
71
- def rcov
72
- deprecate("RSpec::Core::RakeTask#rcov")
73
- @rcov
74
- end
75
-
76
- def rcov=(true_or_false)
77
- deprecate("RSpec::Core::RakeTask#rcov=")
78
- @rcov = true_or_false
79
- end
80
-
81
- # Path to rcov.
82
- #
83
- # default:
84
- # 'rcov'
85
- def rcov_path
86
- deprecate("RSpec::Core::RakeTask#rcov_path")
87
- @rcov_path
88
- end
89
-
90
- def rcov_path=(path)
91
- deprecate("RSpec::Core::RakeTask#rcov_path=")
92
- @rcov_path = path
93
- end
94
-
95
- # Command line options to pass to rcov.
96
- #
97
- # default:
98
- # nil
99
- def rcov_opts
100
- deprecate("RSpec::Core::RakeTask#rcov_opts")
101
- @rcov_opts
102
- end
103
-
104
- def rcov_opts=(opts)
105
- deprecate("RSpec::Core::RakeTask#rcov_opts=")
106
- @rcov_opts = opts
107
- end
108
-
109
51
  # Command line options to pass to ruby.
110
52
  #
111
53
  # default:
@@ -124,42 +66,19 @@ module RSpec
124
66
  # nil
125
67
  attr_accessor :rspec_opts
126
68
 
127
- # @deprecated
128
- # Use rspec_opts instead.
129
- #
130
- # Command line options to pass to rspec.
131
- #
132
- # default:
133
- # nil
134
- def spec_opts=(opts)
135
- deprecate('RSpec::Core::RakeTask#spec_opts=', :replacement => 'rspec_opts=')
136
- @rspec_opts = opts
137
- end
138
-
139
69
  def initialize(*args, &task_block)
140
- setup_ivars(args)
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
141
77
 
142
- desc "Run RSpec code examples" unless ::Rake.application.last_comment
143
-
144
- task name, *args do |_, task_args|
145
- RakeFileUtils.send(:verbose, verbose) do
146
- task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
147
- run_task verbose
148
- end
149
- end
150
- end
151
-
152
- def setup_ivars(args)
153
- @name = args.shift || :spec
154
- @rcov_opts, @ruby_opts, @rspec_opts = nil, nil, nil
155
- @warning, @rcov = false, false
156
- @verbose, @fail_on_error = true, true
157
-
158
- @rcov_path = 'rcov'
159
- @rspec_path = 'rspec'
160
- @pattern = './spec{,/*/**}/*_spec.rb'
78
+ define(args, &task_block)
161
79
  end
162
80
 
81
+ # @private
163
82
  def run_task(verbose)
164
83
  command = spec_command
165
84
 
@@ -169,18 +88,23 @@ module RSpec
169
88
  rescue
170
89
  puts failure_message if failure_message
171
90
  end
172
- abort("#{command} failed") if fail_on_error unless success
91
+ if fail_on_error && !success
92
+ $stderr.puts "#{command} failed"
93
+ exit $?.exitstatus
94
+ end
173
95
  end
174
96
 
175
97
  private
176
98
 
177
- if "".respond_to?(:shellescape)
178
- def shellescape(string)
179
- string.shellescape
180
- end
181
- else # 1.8.6's shellwords doesn't provide shellescape :(.
182
- def shellescape(string)
183
- string.gsub(/"/, '\"').gsub(/'/, "\\\\'")
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
184
108
  end
185
109
  end
186
110
 
@@ -188,7 +112,7 @@ module RSpec
188
112
  if ENV['SPEC']
189
113
  FileList[ ENV['SPEC'] ].sort
190
114
  else
191
- FileList[ pattern ].sort.map { |f| shellescape(f) }
115
+ FileList[ pattern ].sort.map(&:shellescape)
192
116
  end
193
117
  end
194
118
 
@@ -196,35 +120,25 @@ module RSpec
196
120
  cmd_parts = []
197
121
  cmd_parts << RUBY
198
122
  cmd_parts << ruby_opts
199
- cmd_parts << "-w" if @warning
200
- cmd_parts << "-S" << runner
201
- cmd_parts << "-Ispec:lib" << @rcov_opts if @rcov
123
+ cmd_parts << rspec_load_path
124
+ cmd_parts << "-S" << rspec_path
202
125
  cmd_parts << files_to_run
203
- cmd_parts << "--" if @rcov && rspec_opts
204
126
  cmd_parts << rspec_opts
205
127
  cmd_parts.flatten.reject(&blank).join(" ")
206
128
  end
207
129
 
208
- def runner
209
- @rcov ? @rcov_path : rspec_path
210
- end
211
-
212
130
  def blank
213
131
  lambda {|s| s.nil? || s == ""}
214
132
  end
215
133
 
216
- def deprecate deprecated, opts = {}
217
- # unless RSpec is loaded, deprecate won't work (simply requiring the
218
- # deprecate file isn't enough) so this is a check for "is rspec already
219
- # loaded?" "ok use the main deprecate hook" otherwise "simple fallback"
220
- # Note that we don't need rspec to be loaded for the rake task to work
221
- if RSpec.respond_to?(:deprecate)
222
- RSpec.deprecate deprecated, opts
223
- else
224
- warn "DEPRECATION: #{deprecated} is deprecated."
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)}"
225
140
  end
226
141
  end
227
-
228
142
  end
229
143
  end
230
144
  end
@@ -1,135 +1,152 @@
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
- NOTIFICATIONS = %W[start message example_group_started example_group_finished example_started
4
- example_passed example_failed example_pending start_dump dump_pending
5
- dump_failures dump_summary seed close stop deprecation deprecation_summary].map { |n| n.to_sym }
6
-
7
- def initialize(*formatters)
8
- @listeners = Hash.new { |h,k| h[k] = [] }
9
- formatters.each do |formatter|
10
- register_listener(formatter, *NOTIFICATIONS)
11
- end
12
- @example_count = @failure_count = @pending_count = 0
13
- @duration = @start = nil
5
+
6
+ def initialize(configuration)
7
+ @configuration = configuration
8
+ @listeners = Hash.new { |h,k| h[k] = Set.new }
9
+ @examples = []
10
+ @failed_examples = []
11
+ @pending_examples = []
12
+ @duration = @start = @load_time = nil
14
13
  end
15
14
 
16
- # @api
17
- # @param [Object] An obect that wishes to be notified of reporter events
18
- # @param [Array] Array of symbols represents the events a listener wishes to subscribe too
19
- #
15
+ # @private
16
+ attr_reader :examples, :failed_examples, :pending_examples
17
+
20
18
  # Registers a listener to a list of notifications. The reporter will send notification of
21
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
22
23
  def register_listener(listener, *notifications)
23
24
  notifications.each do |notification|
24
- @listeners[notification.to_sym] << listener if listener.respond_to?(notification)
25
+ @listeners[notification.to_sym] << listener
25
26
  end
26
27
  true
27
28
  end
28
29
 
30
+ # @private
29
31
  def registered_listeners(notification)
30
- @listeners[notification]
32
+ @listeners[notification].to_a
31
33
  end
32
34
 
33
35
  # @api
34
36
  # @overload report(count, &block)
35
- # @overload report(count, seed, &block)
36
- # @param [Integer] count the number of examples being run
37
- # @param [Integer] seed the seed used to randomize the spec run
38
- # @param [Block] block yields itself for further reporting.
37
+ # @overload report(count, &block)
38
+ # @param expected_example_count [Integer] the number of examples being run
39
+ # @yield [Block] block yields itself for further reporting.
39
40
  #
40
41
  # Initializes the report run and yields itself for further reporting. The
41
42
  # block is required, so that the reporter can manage cleaning up after the
42
43
  # run.
43
44
  #
44
- # ### Warning:
45
- #
46
- # The `seed` argument is an internal API and is not guaranteed to be
47
- # supported in the future.
48
- #
49
45
  # @example
50
46
  #
51
47
  # reporter.report(group.examples.size) do |r|
52
48
  # example_groups.map {|g| g.run(r) }
53
49
  # end
54
50
  #
55
- def report(expected_example_count, seed=nil)
51
+ def report(expected_example_count)
56
52
  start(expected_example_count)
57
53
  begin
58
54
  yield self
59
55
  ensure
60
- finish(seed)
56
+ finish
61
57
  end
62
58
  end
63
59
 
64
- def start(expected_example_count)
65
- @start = RSpec::Core::Time.now
66
- notify :start, 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)
67
65
  end
68
66
 
67
+ # @private
69
68
  def message(message)
70
- notify :message, message
69
+ notify :message, Notifications::MessageNotification.new(message)
71
70
  end
72
71
 
72
+ # @private
73
73
  def example_group_started(group)
74
- notify :example_group_started, group unless group.descendant_filtered_examples.empty?
74
+ notify :example_group_started, Notifications::GroupNotification.new(group) unless group.descendant_filtered_examples.empty?
75
75
  end
76
76
 
77
+ # @private
77
78
  def example_group_finished(group)
78
- notify :example_group_finished, group unless group.descendant_filtered_examples.empty?
79
+ notify :example_group_finished, Notifications::GroupNotification.new(group) unless group.descendant_filtered_examples.empty?
79
80
  end
80
81
 
82
+ # @private
81
83
  def example_started(example)
82
- @example_count += 1
83
- notify :example_started, example
84
+ @examples << example
85
+ notify :example_started, Notifications::ExampleNotification.for(example)
84
86
  end
85
87
 
88
+ # @private
86
89
  def example_passed(example)
87
- notify :example_passed, example
90
+ notify :example_passed, Notifications::ExampleNotification.for(example)
88
91
  end
89
92
 
93
+ # @private
90
94
  def example_failed(example)
91
- @failure_count += 1
92
- notify :example_failed, example
95
+ @failed_examples << example
96
+ notify :example_failed, Notifications::ExampleNotification.for(example)
93
97
  end
94
98
 
99
+ # @private
95
100
  def example_pending(example)
96
- @pending_count += 1
97
- notify :example_pending, example
101
+ @pending_examples << example
102
+ notify :example_pending, Notifications::ExampleNotification.for(example)
98
103
  end
99
104
 
100
- def deprecation(message)
101
- notify :deprecation, message
105
+ # @private
106
+ def deprecation(hash)
107
+ notify :deprecation, Notifications::DeprecationNotification.from_hash(hash)
102
108
  end
103
109
 
104
- def finish(seed)
110
+ # @private
111
+ def finish
105
112
  begin
106
113
  stop
107
- notify :start_dump
108
- notify :dump_pending
109
- notify :dump_failures
110
- notify :deprecation_summary
111
- notify :dump_summary, @duration, @example_count, @failure_count, @pending_count
112
- notify :seed, seed if seed
114
+ notify :start_dump, Notifications::NullNotification
115
+ notify :dump_pending, Notifications::ExamplesNotification.new(self)
116
+ notify :dump_failures, Notifications::ExamplesNotification.new(self)
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
122
+ notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
113
123
  ensure
114
- notify :close
124
+ notify :close, Notifications::NullNotification
115
125
  end
116
126
  end
117
127
 
118
- def abort(seed)
119
- RSpec.deprecate "RSpec::Core::Reporter#abort", :replacement => "RSpec::Core::Reporter#finish"
120
- finish(seed)
121
- end
122
-
128
+ # @private
123
129
  def stop
124
130
  @duration = (RSpec::Core::Time.now - @start).to_f if @start
125
- notify :stop
131
+ notify :stop, Notifications::ExamplesNotification.new(self)
126
132
  end
127
133
 
128
- def notify(event, *args, &block)
134
+ # @private
135
+ def notify(event, notification)
129
136
  registered_listeners(event).each do |formatter|
130
- formatter.send(event, *args, &block)
137
+ formatter.__send__(event, notification)
131
138
  end
132
139
  end
133
140
 
141
+ private
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
+
148
+ def seed_used?
149
+ @configuration.seed && @configuration.seed_used?
150
+ end
134
151
  end
135
152
  end
@@ -6,6 +6,7 @@ require 'pathname'
6
6
 
7
7
  module RSpec
8
8
  module Core
9
+ # @private
9
10
  module RubyProject
10
11
  def add_to_load_path(*dirs)
11
12
  dirs.map {|dir| add_dir_to_load_path(File.join(root, dir))}
@@ -24,7 +25,7 @@ module RSpec
24
25
  end
25
26
 
26
27
  def find_first_parent_containing(dir)
27
- ascend_until {|path| File.exists?(File.join(path, dir))}
28
+ ascend_until {|path| File.exist?(File.join(path, dir))}
28
29
  end
29
30
 
30
31
  def ascend_until