rspec-core 3.13.5 → 4.0.0.beta1

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 (49) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +56 -1
  4. data/LICENSE.md +2 -2
  5. data/README.md +33 -44
  6. data/lib/rspec/core/bisect/example_minimizer.rb +3 -3
  7. data/lib/rspec/core/bisect/fork_runner.rb +0 -6
  8. data/lib/rspec/core/bisect/shell_command.rb +2 -0
  9. data/lib/rspec/core/bisect/shell_runner.rb +2 -25
  10. data/lib/rspec/core/bisect/utilities.rb +3 -7
  11. data/lib/rspec/core/configuration.rb +128 -330
  12. data/lib/rspec/core/configuration_options.rb +4 -16
  13. data/lib/rspec/core/drb.rb +0 -5
  14. data/lib/rspec/core/dsl.rb +3 -48
  15. data/lib/rspec/core/example.rb +5 -41
  16. data/lib/rspec/core/example_group.rb +36 -75
  17. data/lib/rspec/core/filter_manager.rb +2 -11
  18. data/lib/rspec/core/formatters/deprecation_formatter.rb +4 -4
  19. data/lib/rspec/core/formatters/exception_presenter.rb +30 -60
  20. data/lib/rspec/core/formatters/helpers.rb +1 -1
  21. data/lib/rspec/core/formatters/html_printer.rb +8 -7
  22. data/lib/rspec/core/formatters/html_snippet_extractor.rb +0 -4
  23. data/lib/rspec/core/formatters/profile_formatter.rb +2 -2
  24. data/lib/rspec/core/formatters/snippet_extractor.rb +3 -1
  25. data/lib/rspec/core/formatters/syntax_highlighter.rb +2 -0
  26. data/lib/rspec/core/formatters.rb +4 -8
  27. data/lib/rspec/core/hooks.rb +24 -45
  28. data/lib/rspec/core/memoized_helpers.rb +30 -120
  29. data/lib/rspec/core/metadata.rb +8 -216
  30. data/lib/rspec/core/metadata_filter.rb +15 -69
  31. data/lib/rspec/core/minitest_assertions_adapter.rb +2 -2
  32. data/lib/rspec/core/mocking_adapters/mocha.rb +2 -31
  33. data/lib/rspec/core/notifications.rb +4 -16
  34. data/lib/rspec/core/option_parser.rb +6 -14
  35. data/lib/rspec/core/ordering.rb +5 -6
  36. data/lib/rspec/core/output_wrapper.rb +2 -2
  37. data/lib/rspec/core/pending.rb +1 -9
  38. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +14 -31
  39. data/lib/rspec/core/rake_task.rb +6 -7
  40. data/lib/rspec/core/shared_example_group.rb +7 -82
  41. data/lib/rspec/core/shell_escape.rb +2 -0
  42. data/lib/rspec/core/test_unit_assertions_adapter.rb +4 -17
  43. data/lib/rspec/core/version.rb +1 -1
  44. data/lib/rspec/core/world.rb +8 -23
  45. data/lib/rspec/core.rb +1 -22
  46. data.tar.gz.sig +0 -0
  47. metadata +24 -25
  48. metadata.gz.sig +0 -0
  49. data/lib/rspec/core/flat_map.rb +0 -20
@@ -2,6 +2,7 @@ RSpec::Support.require_rspec_core "backtrace_formatter"
2
2
  RSpec::Support.require_rspec_core "ruby_project"
3
3
  RSpec::Support.require_rspec_core "formatters/deprecation_formatter"
4
4
  RSpec::Support.require_rspec_core "output_wrapper"
5
+ RSpec::Support.require_rspec_support 'ruby_features'
5
6
 
6
7
  module RSpec
7
8
  module Core
@@ -137,27 +138,6 @@ module RSpec
137
138
  # Default: `$stderr`.
138
139
  add_setting :error_stream
139
140
 
140
- # Indicates if the DSL has been exposed off of modules and `main`.
141
- # Default: true
142
- # @return [Boolean]
143
- def expose_dsl_globally?
144
- Core::DSL.exposed_globally?
145
- end
146
-
147
- # Use this to expose the core RSpec DSL via `Module` and the `main`
148
- # object. It will be set automatically but you can override it to
149
- # remove the DSL.
150
- # Default: true
151
- def expose_dsl_globally=(value)
152
- if value
153
- Core::DSL.expose_globally!
154
- Core::SharedExampleGroup::TopLevelDSL.expose_globally!
155
- else
156
- Core::DSL.remove_globally!
157
- Core::SharedExampleGroup::TopLevelDSL.remove_globally!
158
- end
159
- end
160
-
161
141
  # Determines where deprecation warnings are printed.
162
142
  # Defaults to `$stderr`.
163
143
  # @return [IO, String] IO or filename to write to
@@ -168,10 +148,10 @@ module RSpec
168
148
  def deprecation_stream=(value)
169
149
  if @reporter && !value.equal?(@deprecation_stream)
170
150
  warn "RSpec's reporter has already been initialized with " \
171
- "#{deprecation_stream.inspect} as the deprecation stream, so your change to "\
172
- "`deprecation_stream` will be ignored. You should configure it earlier for " \
173
- "it to take effect, or use the `--deprecation-out` CLI option. " \
174
- "(Called from #{CallerFilter.first_non_rspec_line})"
151
+ "#{deprecation_stream.inspect} as the deprecation stream, so your change to " \
152
+ "`deprecation_stream` will be ignored. You should configure it earlier for " \
153
+ "it to take effect, or use the `--deprecation-out` CLI option. " \
154
+ "(Called from #{CallerFilter.first_non_rspec_line})"
175
155
  else
176
156
  @deprecation_stream = value
177
157
  end
@@ -223,11 +203,10 @@ module RSpec
223
203
  @fail_fast = value.to_i
224
204
 
225
205
  if value.to_i == 0
226
- # TODO: in RSpec 4, consider raising an error here.
227
- RSpec.warning "Cannot set `RSpec.configuration.fail_fast`" \
228
- " to `#{value.inspect}`. Only `true`, `false`, `nil` and integers" \
229
- " are valid values."
230
- @fail_fast = true
206
+ raise ArgumentError, "Cannot set `RSpec.configuration.fail_fast` " \
207
+ "to `#{value.inspect}`. Only `true`, `" \
208
+ "`false`, `nil` and integers are valid " \
209
+ "values."
231
210
  end
232
211
  end
233
212
  end
@@ -274,9 +253,9 @@ module RSpec
274
253
  def output_stream=(value)
275
254
  if @reporter && !value.equal?(@output_stream)
276
255
  warn "RSpec's reporter has already been initialized with " \
277
- "#{output_stream.inspect} as the output stream, so your change to "\
278
- "`output_stream` will be ignored. You should configure it earlier for " \
279
- "it to take effect. (Called from #{CallerFilter.first_non_rspec_line})"
256
+ "#{output_stream.inspect} as the output stream, so your change to " \
257
+ "`output_stream` will be ignored. You should configure it earlier for " \
258
+ "it to take effect. (Called from #{CallerFilter.first_non_rspec_line})"
280
259
  else
281
260
  @output_stream = value
282
261
  output_wrapper.output = @output_stream
@@ -322,13 +301,6 @@ module RSpec
322
301
  attr_writer :profile_examples
323
302
  define_predicate :profile_examples
324
303
 
325
- # @macro add_setting
326
- # Run all examples if none match the configured filters
327
- # (default: `false`).
328
- # @deprecated Use {#filter_run_when_matching} instead for the specific
329
- # filters that you want to be ignored if none match.
330
- add_setting :run_all_when_everything_filtered
331
-
332
304
  # @macro add_setting
333
305
  # Color to use to indicate success. Defaults to `:green` but can be set
334
306
  # to one of the following: `[:black, :white, :red, :green, :yellow,
@@ -377,71 +349,6 @@ module RSpec
377
349
  # return [Boolean]
378
350
  add_setting :silence_filter_announcements
379
351
 
380
- # @deprecated This config option was added in RSpec 2 to pave the way
381
- # for this being the default behavior in RSpec 3. Now this option is
382
- # a no-op.
383
- def treat_symbols_as_metadata_keys_with_true_values=(_value)
384
- RSpec.deprecate(
385
- "RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values=",
386
- :message => "RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values= " \
387
- "is deprecated, it is now set to true as default and " \
388
- "setting it to false has no effect."
389
- )
390
- end
391
-
392
- # @macro define_reader
393
- # Configures how RSpec treats metadata passed as part of a shared example
394
- # group definition. For example, given this shared example group definition:
395
- #
396
- # RSpec.shared_context "uses DB", :db => true do
397
- # around(:example) do |ex|
398
- # MyORM.transaction(:rollback => true, &ex)
399
- # end
400
- # end
401
- #
402
- # ...there are two ways RSpec can treat the `:db => true` metadata, each
403
- # of which has a corresponding config option:
404
- #
405
- # 1. `:trigger_inclusion`: this shared context will be implicitly included
406
- # in any groups (or examples) that have `:db => true` metadata.
407
- # 2. `:apply_to_host_groups`: the metadata will be inherited by the metadata
408
- # hash of all host groups and examples.
409
- #
410
- # `:trigger_inclusion` is the legacy behavior from before RSpec 3.5 but should
411
- # be considered deprecated. Instead, you can explicitly include a group with
412
- # `include_context`:
413
- #
414
- # RSpec.describe "My model" do
415
- # include_context "uses DB"
416
- # end
417
- #
418
- # ...or you can configure RSpec to include the context based on matching metadata
419
- # using an API that mirrors configured module inclusion:
420
- #
421
- # RSpec.configure do |rspec|
422
- # rspec.include_context "uses DB", :db => true
423
- # end
424
- #
425
- # `:apply_to_host_groups` is a new feature of RSpec 3.5 and will be the only
426
- # supported behavior in RSpec 4.
427
- #
428
- # @overload shared_context_metadata_behavior
429
- # @return [:trigger_inclusion, :apply_to_host_groups] the configured behavior
430
- # @overload shared_context_metadata_behavior=(value)
431
- # @param value [:trigger_inclusion, :apply_to_host_groups] sets the configured behavior
432
- define_reader :shared_context_metadata_behavior
433
- # @see shared_context_metadata_behavior
434
- def shared_context_metadata_behavior=(value)
435
- case value
436
- when :trigger_inclusion, :apply_to_host_groups
437
- @shared_context_metadata_behavior = value
438
- else
439
- raise ArgumentError, "Cannot set `RSpec.configuration." \
440
- "shared_context_metadata_behavior` to `#{value.inspect}`. Only " \
441
- "`:trigger_inclusion` and `:apply_to_host_groups` are valid values."
442
- end
443
- end
444
-
445
352
  # Record the start time of the spec suite to measure load time.
446
353
  # return [Time]
447
354
  add_setting :start_time
@@ -477,6 +384,12 @@ module RSpec
477
384
  @pending_failure_output = mode
478
385
  end
479
386
 
387
+ # @macro force_line_number_for_spec_rerun
388
+ # Display the line number (`my_spec.rb:10`), as opposed to the example id (`my_spec.rb[1:1:1]`)
389
+ # for shared or nested examples (defaults to `false`).
390
+ # return [Boolean]
391
+ add_setting :force_line_number_for_spec_rerun
392
+
480
393
  # Determines which bisect runner implementation gets used to run subsets
481
394
  # of the suite during a bisection. Your choices are:
482
395
  #
@@ -500,18 +413,15 @@ module RSpec
500
413
  def bisect_runner=(value)
501
414
  if @bisect_runner_class && value != @bisect_runner
502
415
  raise "`config.bisect_runner = #{value.inspect}` can no longer take " \
503
- "effect as the #{@bisect_runner.inspect} bisect runnner is already " \
504
- "in use. This config setting must be set in a file loaded by a " \
505
- "`--require` option (passed at the CLI or in a `.rspec` file) for " \
506
- "it to have any effect."
416
+ "effect as the #{@bisect_runner.inspect} bisect runnner is already " \
417
+ "in use. This config setting must be set in a file loaded by a " \
418
+ "`--require` option (passed at the CLI or in a `.rspec` file) for " \
419
+ "it to have any effect."
507
420
  end
508
421
 
509
422
  @bisect_runner = value
510
423
  end
511
424
 
512
- # @private
513
- # @deprecated Use {#color_mode} = :on, instead of {#color} with {#tty}
514
- add_setting :tty
515
425
  # @private
516
426
  attr_writer :files_to_run
517
427
  # @private
@@ -530,9 +440,9 @@ module RSpec
530
440
  @start_time = $_rspec_core_load_started_at || ::RSpec::Core::Time.now
531
441
  # rubocop:enable Style/GlobalVars
532
442
  @expectation_frameworks = []
533
- @include_modules = FilterableItemRepository::QueryOptimized.new(:any?)
534
- @extend_modules = FilterableItemRepository::QueryOptimized.new(:any?)
535
- @prepend_modules = FilterableItemRepository::QueryOptimized.new(:any?)
443
+ @include_modules = FilterableItemRepository::QueryOptimized.new
444
+ @extend_modules = FilterableItemRepository::QueryOptimized.new
445
+ @prepend_modules = FilterableItemRepository::QueryOptimized.new
536
446
 
537
447
  @bisect_runner = RSpec::Support::RubyFeatures.fork_supported? ? :fork : :shell
538
448
  @bisect_runner_class = nil
@@ -543,7 +453,6 @@ module RSpec
543
453
  @mock_framework = nil
544
454
  @files_or_directories_to_run = []
545
455
  @loaded_spec_files = Set.new
546
- @color = false
547
456
  @color_mode = :automatic
548
457
  @pattern = '**{,/*/**}/*_spec.rb'
549
458
  @exclude_pattern = ''
@@ -573,13 +482,22 @@ module RSpec
573
482
  @profile_examples = false
574
483
  @requires = []
575
484
  @libs = []
576
- @derived_metadata_blocks = FilterableItemRepository::QueryOptimized.new(:any?)
485
+ @derived_metadata_blocks = FilterableItemRepository::QueryOptimized.new
577
486
  @threadsafe = true
578
487
  @max_displayed_failure_line_count = 10
579
488
  @full_cause_backtrace = false
580
489
  @world = World::Null
581
- @shared_context_metadata_behavior = :trigger_inclusion
582
490
  @pending_failure_output = :full
491
+ @force_line_number_for_spec_rerun = false
492
+ @warnings = nil
493
+
494
+ if warnings?
495
+ # Turn on all warnings if warnings already configured
496
+ self.warnings = :all
497
+ else
498
+ # Turn on Ruby deprecations by default
499
+ self.warnings = :deprecations_only
500
+ end
583
501
 
584
502
  define_built_in_hooks
585
503
  end
@@ -865,8 +783,8 @@ module RSpec
865
783
 
866
784
  # Tag this exception class so our exception formatting logic knows
867
785
  # that it satisfies the `MultipleExceptionError` interface.
868
- ::RSpec::Expectations::MultipleExpectationsNotMetError.__send__(
869
- :include, MultipleExceptionError::InterfaceTag
786
+ ::RSpec::Expectations::MultipleExpectationsNotMetError.include(
787
+ MultipleExceptionError::InterfaceTag
870
788
  )
871
789
 
872
790
  ::RSpec::Matchers
@@ -909,20 +827,6 @@ module RSpec
909
827
  @backtrace_formatter.full_backtrace = true_or_false
910
828
  end
911
829
 
912
- # Enables color output if the output is a TTY. As of RSpec 3.6, this is
913
- # the default behavior and this option is retained only for backwards
914
- # compatibility.
915
- #
916
- # @deprecated No longer recommended because of complex behavior. Instead,
917
- # rely on the fact that TTYs will display color by default, or set
918
- # {#color_mode} to :on to display color on a non-TTY output.
919
- # @see color_mode
920
- # @see color_enabled?
921
- # @return [Boolean]
922
- def color
923
- value_for(:color) { @color }
924
- end
925
-
926
830
  # The mode for determining whether to display output in color. One of:
927
831
  #
928
832
  # - :automatic - the output will be in color if the output is a TTY (the
@@ -945,20 +849,13 @@ module RSpec
945
849
  when :on then true
946
850
  when :off then false
947
851
  else # automatic
948
- output_to_tty?(output) || (color && tty?)
852
+ output_to_tty?(output)
949
853
  end
950
854
  end
951
855
 
952
856
  # Set the color mode.
953
857
  attr_writer :color_mode
954
858
 
955
- # Toggle output color.
956
- #
957
- # @deprecated No longer recommended because of complex behavior. Instead,
958
- # rely on the fact that TTYs will display color by default, or set
959
- # {:color_mode} to :on to display color on a non-TTY output.
960
- attr_writer :color
961
-
962
859
  # @private
963
860
  def libs=(libs)
964
861
  libs.map do |lib|
@@ -1201,18 +1098,14 @@ module RSpec
1201
1098
  # RSpec.describe User, :type => :model do
1202
1099
  # end
1203
1100
  #
1204
- # @note The defined aliased will also be added to the top level
1205
- # (e.g. `main` and from within modules) if
1206
- # `expose_dsl_globally` is set to true.
1207
1101
  # @see #alias_example_to
1208
- # @see #expose_dsl_globally=
1209
1102
  def alias_example_group_to(new_name, *args)
1210
1103
  extra_options = Metadata.build_hash_from(args)
1211
1104
  RSpec::Core::ExampleGroup.define_example_group_method(new_name, extra_options)
1212
1105
  end
1213
1106
 
1214
- # Define an alias for it_should_behave_like that allows different
1215
- # language (like "it_has_behavior" or "it_behaves_like") to be
1107
+ # Define an alias for it_behaves_like that allows different
1108
+ # language (like "it_has_behavior" or "it_is_able_to") to be
1216
1109
  # employed when including shared examples.
1217
1110
  #
1218
1111
  # @example
@@ -1234,13 +1127,10 @@ module RSpec
1234
1127
  # # ...sortability examples here
1235
1128
  #
1236
1129
  # @note Use with caution. This extends the language used in your
1237
- # specs, but does not add any additional documentation. We use this
1238
- # in RSpec to define `it_should_behave_like` (for backward
1239
- # compatibility), but we also add docs for that method.
1130
+ # specs, but does not add any additional documentation.
1240
1131
  def alias_it_behaves_like_to(new_name, report_label='')
1241
1132
  RSpec::Core::ExampleGroup.define_nested_shared_group_method(new_name, report_label)
1242
1133
  end
1243
- alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
1244
1134
 
1245
1135
  # Adds key/value pairs to the `inclusion_filter`. If `args`
1246
1136
  # includes any symbols that are not part of the hash, each symbol
@@ -1273,7 +1163,7 @@ module RSpec
1273
1163
  #
1274
1164
  # filter_run_including :foo # same as filter_run_including :foo => true
1275
1165
  def filter_run_including(*args)
1276
- meta = Metadata.build_hash_from(args, :warn_about_example_group_filtering)
1166
+ meta = Metadata.build_hash_from(args)
1277
1167
  filter_manager.include_with_low_priority meta
1278
1168
  static_config_filter_manager.include_with_low_priority Metadata.deep_hash_dup(meta)
1279
1169
  end
@@ -1302,7 +1192,7 @@ module RSpec
1302
1192
  # This overrides any inclusion filters/tags set on the command line or in
1303
1193
  # configuration files.
1304
1194
  def inclusion_filter=(filter)
1305
- meta = Metadata.build_hash_from([filter], :warn_about_example_group_filtering)
1195
+ meta = Metadata.build_hash_from([filter])
1306
1196
  filter_manager.include_only meta
1307
1197
  end
1308
1198
 
@@ -1347,7 +1237,7 @@ module RSpec
1347
1237
  #
1348
1238
  # filter_run_excluding :foo # same as filter_run_excluding :foo => true
1349
1239
  def filter_run_excluding(*args)
1350
- meta = Metadata.build_hash_from(args, :warn_about_example_group_filtering)
1240
+ meta = Metadata.build_hash_from(args)
1351
1241
  filter_manager.exclude_with_low_priority meta
1352
1242
  static_config_filter_manager.exclude_with_low_priority Metadata.deep_hash_dup(meta)
1353
1243
  end
@@ -1360,7 +1250,7 @@ module RSpec
1360
1250
  # This overrides any exclusion filters/tags set on the command line or in
1361
1251
  # configuration files.
1362
1252
  def exclusion_filter=(filter)
1363
- meta = Metadata.build_hash_from([filter], :warn_about_example_group_filtering)
1253
+ meta = Metadata.build_hash_from([filter])
1364
1254
  filter_manager.exclude_only meta
1365
1255
  end
1366
1256
 
@@ -1521,43 +1411,41 @@ module RSpec
1521
1411
  end
1522
1412
  end
1523
1413
 
1524
- if RSpec::Support::RubyFeatures.module_prepends_supported?
1525
- # Tells RSpec to prepend example groups with `mod`. Methods defined in
1526
- # `mod` are exposed to examples (not example groups). Use `filters` to
1527
- # constrain the groups in which to prepend the module.
1528
- #
1529
- # Similar to `include`, but module is included before the example group's class
1530
- # in the ancestor chain.
1531
- #
1532
- # @example
1533
- #
1534
- # module OverrideMod
1535
- # def override_me
1536
- # "overridden"
1537
- # end
1538
- # end
1539
- #
1540
- # RSpec.configure do |config|
1541
- # config.prepend(OverrideMod, :method => :prepend)
1542
- # end
1543
- #
1544
- # describe "overriding example's class", :method => :prepend do
1545
- # it "finds the user" do
1546
- # self.class.class_eval do
1547
- # def override_me
1548
- # end
1549
- # end
1550
- # override_me # => "overridden"
1551
- # # ...
1552
- # end
1553
- # end
1554
- #
1555
- # @see #include
1556
- # @see #extend
1557
- def prepend(mod, *filters)
1558
- define_mixed_in_module(mod, filters, @prepend_modules, :prepend) do |group|
1559
- safe_prepend(mod, group)
1560
- end
1414
+ # Tells RSpec to prepend example groups with `mod`. Methods defined in
1415
+ # `mod` are exposed to examples (not example groups). Use `filters` to
1416
+ # constrain the groups in which to prepend the module.
1417
+ #
1418
+ # Similar to `include`, but module is included before the example group's class
1419
+ # in the ancestor chain.
1420
+ #
1421
+ # @example
1422
+ #
1423
+ # module OverrideMod
1424
+ # def override_me
1425
+ # "overridden"
1426
+ # end
1427
+ # end
1428
+ #
1429
+ # RSpec.configure do |config|
1430
+ # config.prepend(OverrideMod, :method => :prepend)
1431
+ # end
1432
+ #
1433
+ # describe "overriding example's class", :method => :prepend do
1434
+ # it "finds the user" do
1435
+ # self.class.class_eval do
1436
+ # def override_me
1437
+ # end
1438
+ # end
1439
+ # override_me # => "overridden"
1440
+ # # ...
1441
+ # end
1442
+ # end
1443
+ #
1444
+ # @see #include
1445
+ # @see #extend
1446
+ def prepend(mod, *filters)
1447
+ define_mixed_in_module(mod, filters, @prepend_modules, :prepend) do |group|
1448
+ safe_prepend(mod, group)
1561
1449
  end
1562
1450
  end
1563
1451
 
@@ -1614,16 +1502,14 @@ module RSpec
1614
1502
 
1615
1503
  # @private
1616
1504
  def configure_mock_framework
1617
- RSpec::Core::ExampleGroup.__send__(:include, mock_framework)
1618
- conditionally_disable_mocks_monkey_patching
1505
+ RSpec::Core::ExampleGroup.include(mock_framework)
1619
1506
  end
1620
1507
 
1621
1508
  # @private
1622
1509
  def configure_expectation_framework
1623
1510
  expectation_frameworks.each do |framework|
1624
- RSpec::Core::ExampleGroup.__send__(:include, framework)
1511
+ RSpec::Core::ExampleGroup.include(framework)
1625
1512
  end
1626
- conditionally_disable_expectations_monkey_patching
1627
1513
  end
1628
1514
 
1629
1515
  # @private
@@ -1756,11 +1642,37 @@ module RSpec
1756
1642
  # @private
1757
1643
  delegate_to_ordering_manager :seed_used?, :ordering_registry
1758
1644
 
1759
- # Set Ruby warnings on or off.
1645
+ # Set Ruby warnings. `:deprecations_only` is recommended, but may be too
1646
+ # noisy due to dependencies.
1647
+ # Can be set to `:all` or `:none` to show all warnings or none of them.
1760
1648
  def warnings=(value)
1761
- $VERBOSE = !!value
1649
+ case value
1650
+ when :none
1651
+ @warnings = :none
1652
+ $VERBOSE = false
1653
+ ::Warning[:deprecated] = false
1654
+ when :all
1655
+ @warnings = :all
1656
+ $VERBOSE = true
1657
+ ::Warning[:deprecated] = true
1658
+ when :deprecations_only
1659
+ @warnings = :deprecations_only
1660
+ $VERBOSE = false
1661
+ ::Warning[:deprecated] = true
1662
+ else
1663
+ raise "Unsupported value for `warnings` (#{value.inspect}). " \
1664
+ "Only `:none`, `:all` and `:deprecations_only` are supported."
1665
+ end
1666
+ end
1667
+
1668
+ # @return [Boolean] Whether or not ruby deprecations are enabled.
1669
+ def deprecation_warnings?
1670
+ ::Warning[:deprecated]
1762
1671
  end
1763
1672
 
1673
+ # @return [Symbol] The configured warning level
1674
+ attr_reader :warnings
1675
+
1764
1676
  # @return [Boolean] Whether or not ruby warnings are enabled.
1765
1677
  def warnings?
1766
1678
  $VERBOSE
@@ -1811,6 +1723,7 @@ module RSpec
1811
1723
  def expose_current_running_example_as(method_name)
1812
1724
  ExposeCurrentExample.module_exec do
1813
1725
  extend RSpec::SharedContext
1726
+
1814
1727
  let(method_name) { |ex| ex }
1815
1728
  end
1816
1729
 
@@ -1834,52 +1747,6 @@ module RSpec
1834
1747
  self.deprecation_stream = Formatters::DeprecationFormatter::RaiseErrorStream.new
1835
1748
  end
1836
1749
 
1837
- # Enables zero monkey patching mode for RSpec. It removes monkey
1838
- # patching of the top-level DSL methods (`describe`,
1839
- # `shared_examples_for`, etc) onto `main` and `Module`, instead
1840
- # requiring you to prefix these methods with `RSpec.`. It enables
1841
- # expect-only syntax for rspec-mocks and rspec-expectations. It
1842
- # simply disables monkey patching on whatever pieces of RSpec
1843
- # the user is using.
1844
- #
1845
- # @note It configures rspec-mocks and rspec-expectations only
1846
- # if the user is using those (either explicitly or implicitly
1847
- # by not setting `mock_with` or `expect_with` to anything else).
1848
- #
1849
- # @note If the user uses this options with `mock_with :mocha`
1850
- # (or similar) they will still have monkey patching active
1851
- # in their test environment from mocha.
1852
- #
1853
- # @example
1854
- #
1855
- # # It disables all monkey patching.
1856
- # RSpec.configure do |config|
1857
- # config.disable_monkey_patching!
1858
- # end
1859
- #
1860
- # # Is an equivalent to
1861
- # RSpec.configure do |config|
1862
- # config.expose_dsl_globally = false
1863
- #
1864
- # config.mock_with :rspec do |mocks|
1865
- # mocks.syntax = :expect
1866
- # mocks.patch_marshal_to_support_partial_doubles = false
1867
- # end
1868
- #
1869
- # config.expect_with :rspec do |expectations|
1870
- # expectations.syntax = :expect
1871
- # end
1872
- # end
1873
- def disable_monkey_patching!
1874
- self.expose_dsl_globally = false
1875
- self.disable_monkey_patching = true
1876
- conditionally_disable_mocks_monkey_patching
1877
- conditionally_disable_expectations_monkey_patching
1878
- end
1879
-
1880
- # @private
1881
- attr_accessor :disable_monkey_patching
1882
-
1883
1750
  # Defines a callback that can assign derived metadata values.
1884
1751
  #
1885
1752
  # @param filters [Array<Symbol>, Hash] metadata filters that determine
@@ -1898,7 +1765,7 @@ module RSpec
1898
1765
  # end
1899
1766
  # end
1900
1767
  def define_derived_metadata(*filters, &block)
1901
- meta = Metadata.build_hash_from(filters, :warn_about_example_group_filtering)
1768
+ meta = Metadata.build_hash_from(filters)
1902
1769
  @derived_metadata_blocks.append(block, meta)
1903
1770
  end
1904
1771
 
@@ -1921,7 +1788,7 @@ module RSpec
1921
1788
  # end
1922
1789
  # end
1923
1790
  def when_first_matching_example_defined(*filters)
1924
- specified_meta = Metadata.build_hash_from(filters, :warn_about_example_group_filtering)
1791
+ specified_meta = Metadata.build_hash_from(filters)
1925
1792
 
1926
1793
  callback = lambda do |example_or_group_meta|
1927
1794
  # Example groups do not have `:example_group` metadata
@@ -1977,12 +1844,6 @@ module RSpec
1977
1844
  handle_suite_hook(scope, meta) do
1978
1845
  @before_suite_hooks << Hooks::BeforeHook.new(block, {})
1979
1846
  end || begin
1980
- # defeat Ruby 2.5 lazy proc allocation to ensure
1981
- # the methods below are passed the same proc instances
1982
- # so `Hook` equality is preserved. For more info, see:
1983
- # https://bugs.ruby-lang.org/issues/14045#note-5
1984
- block.__id__
1985
-
1986
1847
  add_hook_to_existing_matching_groups(meta, scope) { |g| g.before(scope, *meta, &block) }
1987
1848
  super(scope, *meta, &block)
1988
1849
  end
@@ -2007,12 +1868,6 @@ module RSpec
2007
1868
  handle_suite_hook(scope, meta) do
2008
1869
  @before_suite_hooks.unshift Hooks::BeforeHook.new(block, {})
2009
1870
  end || begin
2010
- # defeat Ruby 2.5 lazy proc allocation to ensure
2011
- # the methods below are passed the same proc instances
2012
- # so `Hook` equality is preserved. For more info, see:
2013
- # https://bugs.ruby-lang.org/issues/14045#note-5
2014
- block.__id__
2015
-
2016
1871
  add_hook_to_existing_matching_groups(meta, scope) { |g| g.prepend_before(scope, *meta, &block) }
2017
1872
  super(scope, *meta, &block)
2018
1873
  end
@@ -2032,12 +1887,6 @@ module RSpec
2032
1887
  handle_suite_hook(scope, meta) do
2033
1888
  @after_suite_hooks.unshift Hooks::AfterHook.new(block, {})
2034
1889
  end || begin
2035
- # defeat Ruby 2.5 lazy proc allocation to ensure
2036
- # the methods below are passed the same proc instances
2037
- # so `Hook` equality is preserved. For more info, see:
2038
- # https://bugs.ruby-lang.org/issues/14045#note-5
2039
- block.__id__
2040
-
2041
1890
  add_hook_to_existing_matching_groups(meta, scope) { |g| g.after(scope, *meta, &block) }
2042
1891
  super(scope, *meta, &block)
2043
1892
  end
@@ -2062,12 +1911,6 @@ module RSpec
2062
1911
  handle_suite_hook(scope, meta) do
2063
1912
  @after_suite_hooks << Hooks::AfterHook.new(block, {})
2064
1913
  end || begin
2065
- # defeat Ruby 2.5 lazy proc allocation to ensure
2066
- # the methods below are passed the same proc instances
2067
- # so `Hook` equality is preserved. For more info, see:
2068
- # https://bugs.ruby-lang.org/issues/14045#note-5
2069
- block.__id__
2070
-
2071
1914
  add_hook_to_existing_matching_groups(meta, scope) { |g| g.append_after(scope, *meta, &block) }
2072
1915
  super(scope, *meta, &block)
2073
1916
  end
@@ -2077,12 +1920,6 @@ module RSpec
2077
1920
  #
2078
1921
  # See {Hooks#around} for full `around` hook docs.
2079
1922
  def around(scope=nil, *meta, &block)
2080
- # defeat Ruby 2.5 lazy proc allocation to ensure
2081
- # the methods below are passed the same proc instances
2082
- # so `Hook` equality is preserved. For more info, see:
2083
- # https://bugs.ruby-lang.org/issues/14045#note-5
2084
- block.__id__
2085
-
2086
1923
  add_hook_to_existing_matching_groups(meta, scope) { |g| g.around(scope, *meta, &block) }
2087
1924
  super(scope, *meta, &block)
2088
1925
  end
@@ -2172,12 +2009,10 @@ module RSpec
2172
2009
  return nil unless scope == :suite
2173
2010
 
2174
2011
  unless meta.empty?
2175
- # TODO: in RSpec 4, consider raising an error here.
2176
- # We warn only for backwards compatibility.
2177
- RSpec.warn_with "WARNING: `:suite` hooks do not support metadata since " \
2178
- "they apply to the suite as a whole rather than " \
2179
- "any individual example or example group that has metadata. " \
2180
- "The metadata you have provided (#{meta.inspect}) will be ignored."
2012
+ raise ArgumentError, "WARNING: `:suite` hooks do not support metadata since " \
2013
+ "they apply to the suite as a whole rather than " \
2014
+ "any individual example or example group that has metadata. " \
2015
+ "The metadata you have provided (#{meta.inspect}) will be ignored."
2181
2016
  end
2182
2017
 
2183
2018
  yield
@@ -2202,7 +2037,7 @@ module RSpec
2202
2037
  end
2203
2038
 
2204
2039
  def get_files_to_run(paths)
2205
- files = FlatMap.flat_map(paths_to_check(paths)) do |path|
2040
+ files = paths_to_check(paths).flat_map do |path|
2206
2041
  path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
2207
2042
  File.directory?(path) ? gather_directories(path) : extract_location(path)
2208
2043
  end.uniq
@@ -2308,29 +2143,6 @@ module RSpec
2308
2143
  output.respond_to?(:tty?) && output.tty?
2309
2144
  end
2310
2145
 
2311
- def conditionally_disable_mocks_monkey_patching
2312
- return unless disable_monkey_patching && rspec_mocks_loaded?
2313
-
2314
- RSpec::Mocks.configuration.tap do |config|
2315
- config.syntax = :expect
2316
- config.patch_marshal_to_support_partial_doubles = false
2317
- end
2318
- end
2319
-
2320
- def conditionally_disable_expectations_monkey_patching
2321
- return unless disable_monkey_patching && rspec_expectations_loaded?
2322
-
2323
- RSpec::Expectations.configuration.syntax = :expect
2324
- end
2325
-
2326
- def rspec_mocks_loaded?
2327
- defined?(RSpec::Mocks.configuration)
2328
- end
2329
-
2330
- def rspec_expectations_loaded?
2331
- defined?(RSpec::Expectations.configuration)
2332
- end
2333
-
2334
2146
  def update_pattern_attr(name, value)
2335
2147
  if @spec_files_loaded
2336
2148
  RSpec.warning "Configuring `#{name}` to #{value} has no effect since " \
@@ -2375,33 +2187,19 @@ module RSpec
2375
2187
  end
2376
2188
 
2377
2189
  def metadata_applies_to_group?(meta, group)
2378
- meta.empty? || MetadataFilter.apply?(:any?, meta, group.metadata)
2190
+ meta.empty? || MetadataFilter.apply?(meta, group.metadata)
2379
2191
  end
2380
2192
 
2381
- if RSpec::Support::RubyFeatures.module_prepends_supported?
2382
- def safe_prepend(mod, host)
2383
- host.__send__(:prepend, mod) unless host < mod
2384
- end
2193
+ def safe_prepend(mod, host)
2194
+ host.prepend(mod) unless host < mod
2385
2195
  end
2386
2196
 
2387
- if RUBY_VERSION.to_f >= 1.9
2388
- def safe_include(mod, host)
2389
- host.__send__(:include, mod) unless host < mod
2390
- end
2391
-
2392
- def safe_extend(mod, host)
2393
- host.extend(mod) unless host.singleton_class < mod
2394
- end
2395
- else # for 1.8.7
2396
- # :nocov:
2397
- def safe_include(mod, host)
2398
- host.__send__(:include, mod) unless host.included_modules.include?(mod)
2399
- end
2197
+ def safe_include(mod, host)
2198
+ host.include(mod) unless host < mod
2199
+ end
2400
2200
 
2401
- def safe_extend(mod, host)
2402
- host.extend(mod) unless (class << host; self; end).included_modules.include?(mod)
2403
- end
2404
- # :nocov:
2201
+ def safe_extend(mod, host)
2202
+ host.extend(mod) unless host.singleton_class < mod
2405
2203
  end
2406
2204
 
2407
2205
  def define_mixed_in_module(mod, filters, mod_list, config_method, &block)
@@ -2409,7 +2207,7 @@ module RSpec
2409
2207
  raise TypeError, "`RSpec.configuration.#{config_method}` expects a module but got: #{mod.inspect}"
2410
2208
  end
2411
2209
 
2412
- meta = Metadata.build_hash_from(filters, :warn_about_example_group_filtering)
2210
+ meta = Metadata.build_hash_from(filters)
2413
2211
  mod_list.append(mod, meta)
2414
2212
  on_existing_matching_groups(meta, &block)
2415
2213
  end