Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit b5b3876

Browse files
committed
Add RSpec 4 deprecation warnings
See rspec/rspec#61
1 parent ea8554a commit b5b3876

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

lib/rspec/core/configuration.rb

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,13 @@ def exclude_pattern=(value)
327327
# (default: `false`).
328328
# @deprecated Use {#filter_run_when_matching} instead for the specific
329329
# filters that you want to be ignored if none match.
330-
add_setting :run_all_when_everything_filtered
330+
def run_all_when_everything_filtered=(value)
331+
RSpec.deprecate("`run_all_when_everything_filtered` setting is deprecated and will be removed in RSpec 4. " \
332+
"Use `filter_run_when_matching = :focus` instead.")
333+
@run_all_when_everything_filtered = value
334+
end
335+
define_reader :run_all_when_everything_filtered
336+
define_predicate :run_all_when_everything_filtered
331337

332338
# @macro add_setting
333339
# Color to use to indicate success. Defaults to `:green` but can be set
@@ -440,6 +446,9 @@ def shared_context_metadata_behavior=(value)
440446
"shared_context_metadata_behavior` to `#{value.inspect}`. Only " \
441447
"`:trigger_inclusion` and `:apply_to_host_groups` are valid values."
442448
end
449+
450+
RSpec.deprecate("`shared_context_metadata_behavior` setting is deprecated, and will be removed in RSpec 4. "\
451+
"`:apply_to_host_groups` will become the default and only option.")
443452
end
444453

445454
# Record the start time of the spec suite to measure load time.
@@ -493,6 +502,14 @@ def bisect_runner=(value)
493502
# @private
494503
# @deprecated Use {#color_mode} = :on, instead of {#color} with {#tty}
495504
add_setting :tty
505+
def tty=(value)
506+
RSpec.deprecate("`tty` setting is deprecated and will be removed in RSpec 4. " \
507+
"Use `color_mode` instead.")
508+
@tty = value
509+
end
510+
define_reader :tty
511+
define_predicate :tty
512+
496513
# @private
497514
attr_writer :files_to_run
498515
# @private
@@ -934,7 +951,11 @@ def color_enabled?(output=output_stream)
934951
# @deprecated No longer recommended because of complex behavior. Instead,
935952
# rely on the fact that TTYs will display color by default, or set
936953
# {:color_mode} to :on to display color on a non-TTY output.
937-
attr_writer :color
954+
def color=(value)
955+
RSpec.deprecate("`color` setting is deprecated and will be removed in RSpec 4. " \
956+
"Use `color_mode` instead.")
957+
@color = value
958+
end
938959

939960
# @private
940961
def libs=(libs)
@@ -1217,7 +1238,11 @@ def alias_example_group_to(new_name, *args)
12171238
def alias_it_behaves_like_to(new_name, report_label='')
12181239
RSpec::Core::ExampleGroup.define_nested_shared_group_method(new_name, report_label)
12191240
end
1220-
alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
1241+
def alias_it_should_behave_like_to(new_name, report_label='')
1242+
RSpec.deprecate("`alias_it_should_behave_like_to` is deprecated, and will be removed in RSpec 4. "\
1243+
"Use `alias_it_behaves_like_to` instead.")
1244+
alias_it_behaves_like_to(new_name, report_label)
1245+
end
12211246

12221247
# Adds key/value pairs to the `inclusion_filter`. If `args`
12231248
# includes any symbols that are not part of the hash, each symbol

lib/rspec/core/dsl.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class << self
5858
def self.expose_globally!
5959
return if exposed_globally?
6060

61+
RSpec.deprecate("Globally-exposed DSL is deprecated and will be removed in RSpec 4")
62+
6163
example_group_aliases.each do |method_name|
6264
expose_example_group_alias_globally(method_name)
6365
end

lib/rspec/core/example.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def location_rerun_argument
109109
# @note If there are multiple examples identified by this location, they will use {#id}
110110
# to rerun instead, but this method will still return the location (that's why it is deprecated!).
111111
def rerun_argument
112+
RSpec.deprecate("`rerun_argument` is deprecated, and will be removed in RSpec 4. "\
113+
"Use `location_rerun_argument` instead.")
112114
location_rerun_argument
113115
end
114116

lib/rspec/core/example_group.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,10 @@ def self.define_example_group_method(name, metadata={})
314314
# @!scope class
315315
#
316316
# @see SharedExampleGroup
317-
def self.define_nested_shared_group_method(new_name, report_label="it should behave like")
317+
def self.define_nested_shared_group_method(new_name, report_label="it should behave like", &block)
318318
idempotently_define_singleton_method(new_name) do |name, *args, &customization_block|
319+
yield if block_given? # to print a deprecation warning for it_should_behave_like usage
320+
319321
# Pass :caller so the :location metadata is set properly.
320322
# Otherwise, it'll be set to the next line because that's
321323
# the block's source_location.
@@ -332,7 +334,10 @@ def self.define_nested_shared_group_method(new_name, report_label="it should beh
332334
define_nested_shared_group_method :it_behaves_like, "behaves like"
333335
# Generates a nested example group and includes the shared content
334336
# mapped to `name` in the nested group.
335-
define_nested_shared_group_method :it_should_behave_like
337+
define_nested_shared_group_method(:it_should_behave_like) do
338+
RSpec.deprecate("`it_should_behave_like` is deprecated, and will be removed in RSpec 4. "\
339+
"Use `it_behaves_like` instead.")
340+
end
336341

337342
# Includes shared content mapped to `name` directly in the group in which
338343
# it is declared, as opposed to `it_behaves_like`, which creates a nested
@@ -517,6 +522,9 @@ def self.top_level?
517522
# @private
518523
def self.ensure_example_groups_are_configured
519524
unless defined?(@@example_groups_configured)
525+
unless RSpec.configuration.disable_monkey_patching
526+
RSpec.deprecate("Monkey-patching mode is deprecated, and will be removed in RSpec 4")
527+
end
520528
RSpec.configuration.configure_mock_framework
521529
RSpec.configuration.configure_expectation_framework
522530
# rubocop:disable Style/ClassVars

lib/rspec/core/filter_manager.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ def add_path_to_arrays_filter(filter_key, path, values)
8989
def prune_conditionally_filtered_examples(examples)
9090
examples.reject do |ex|
9191
meta = ex.metadata
92+
if meta.key?(:if)
93+
RSpec.deprecate("`:if` metadata is deprecated and will have no special meaning in RSpec 4. " \
94+
"Use `:skip` with a negated condition instead.")
95+
end
96+
if meta.key?(:unless)
97+
RSpec.deprecate("`:if` metadata is deprecated and will have no special meaning in RSpec 4. " \
98+
"Use `:skip` instead.")
99+
end
92100
!meta.fetch(:if, true) || meta[:unless]
93101
end
94102
end

lib/rspec/core/memoized_helpers.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def subject
7979
# want to use `is_expected.to` instead of `should`.
8080
def should(matcher=nil, message=nil)
8181
enforce_value_expectation(matcher, 'should')
82+
RSpec.deprecate("Monkey-patching `should` is deprecated, and will be removed in RSpec 4")
8283
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(subject, matcher, message)
8384
end
8485

@@ -99,6 +100,7 @@ def should(matcher=nil, message=nil)
99100
# want to use `is_expected.to_not` instead of `should_not`.
100101
def should_not(matcher=nil, message=nil)
101102
enforce_value_expectation(matcher, 'should_not')
103+
RSpec.deprecate("Monkey-patching `should_not` is deprecated, and will be removed in RSpec 4")
102104
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(subject, matcher, message)
103105
end
104106

0 commit comments

Comments
 (0)