Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecations #2864

Merged
merged 10 commits into from
Feb 20, 2021
12 changes: 12 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ Breaking Changes:
execution result. (Phil Pirozhkov, #2862)
* Skip setting the default pattern from Rake task. (Phil Pirozhkov, #2868)
* Remove special `:if`/`:unless` filtering metadata. (Phil Pirozhkov, #2870)
* Remove deprecated `color` configuration option and `--color` command line
option. (Phil Pirozhkov, #2864)
* Remove `it_should_behave_like` nested shared group method and
`alias_it_should_behave_like_to` configuration option. (Phil Pirozhkov, #2864)
* Remove deprecated `treat_symbols_as_metadata_keys_with_true_values` configuration
option. (Phil Pirozhkov, #2864)
* Remove support for Mocha version < 1.0. (Phil Pirozhkov, #2864)
* Remove deprecated `PendingExampleFixedNotification` and
`PendingExampleFailedAsExpectedNotification` classes. (Phil Pirozhkov, #2864)
* Remove deprecated `rerun_argument` example method. (Phil Pirozhkov, #2864)
* Raise on attempt to use a legacy formatter without `rspec-legacy_formatters`.
(Phil Pirozhkov, #2864)

Enhancements:

Expand Down
13 changes: 6 additions & 7 deletions features/example_groups/shared_examples.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Feature: shared examples
```ruby
include_examples "name" # include the examples in the current context
it_behaves_like "name" # include the examples in a nested context
it_should_behave_like "name" # include the examples in a nested context
matching metadata # include the examples in the current context
```

Expand Down Expand Up @@ -206,34 +205,34 @@ Feature: shared examples

RSpec.describe Array, "with 3 items" do
subject { [1, 2, 3] }
it_should_behave_like "a measurable object", 3, [:size, :length]
it_behaves_like "a measurable object", 3, [:size, :length]
end

RSpec.describe String, "of 6 characters" do
subject { "FooBar" }
it_should_behave_like "a measurable object", 6, [:size, :length]
it_behaves_like "a measurable object", 6, [:size, :length]
end
"""
When I run `rspec shared_example_group_params_spec.rb --format documentation`
Then the examples should all pass
And the output should contain:
"""
Array with 3 items
it should behave like a measurable object
behaves like a measurable object
should return 3 from #size
should return 3 from #length

String of 6 characters
it should behave like a measurable object
behaves like a measurable object
should return 6 from #size
should return 6 from #length
"""

Scenario: Aliasing `it_should_behave_like` to `it_has_behavior`
Scenario: Aliasing `it_behaves_like` to `it_has_behavior`
Given a file named "shared_example_group_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
c.alias_it_behaves_like_to :it_has_behavior, 'has behavior:'
end

RSpec.shared_examples 'sortability' do
Expand Down
2 changes: 1 addition & 1 deletion features/formatters/custom_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: custom formatters
"""ruby
class CustomFormatter
# This registers the notifications this formatter supports, and tells
# us that this was written against the RSpec 3.x formatter API.
# us that this was written against the RSpec >= 3.x formatter API.
RSpec::Core::Formatters.register self, :example_started

def initialize(output)
Expand Down
18 changes: 1 addition & 17 deletions lib/rspec/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,7 @@ def self.configure
# The example being executed.
#
# The primary audience for this method is library authors who need access
# to the example currently being executed and also want to support RSpec 2.
#
# @example support for RSpec version 2
#
# RSpec.configure do |c|
# # context.example is deprecated, but RSpec.current_example is not
# # available until RSpec 3.0.
# fetch_current_example = RSpec.respond_to?(:current_example) ?
# proc { RSpec.current_example } : proc { |context| context.example }
#
# c.before(:example) do
# example = fetch_current_example.call(self)
#
# # ...
# end
# end
#
# to the example currently being executed.
JonRowe marked this conversation as resolved.
Show resolved Hide resolved
def self.current_example
RSpec::Support.thread_local_data[:current_example]
end
Expand Down
48 changes: 4 additions & 44 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,6 @@ def exclude_pattern=(value)
# return [Boolean]
add_setting :silence_filter_announcements

# @deprecated This config option was added in RSpec 2 to pave the way
# for this being the default behavior in RSpec 3. Now this option is
# a no-op.
def treat_symbols_as_metadata_keys_with_true_values=(_value)
RSpec.deprecate(
"RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values=",
:message => "RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values= " \
"is deprecated, it is now set to true as default and " \
"setting it to false has no effect."
)
end

# Record the start time of the spec suite to measure load time.
# return [Time]
add_setting :start_time
Expand Down Expand Up @@ -408,9 +396,6 @@ def bisect_runner=(value)
@bisect_runner = value
end

# @private
# @deprecated Use {#color_mode} = :on, instead of {#color} with {#tty}
add_setting :tty
# @private
attr_writer :files_to_run
# @private
Expand Down Expand Up @@ -441,7 +426,6 @@ def initialize
@mock_framework = nil
@files_or_directories_to_run = []
@loaded_spec_files = Set.new
@color = false
@color_mode = :automatic
@pattern = '**{,/*/**}/*_spec.rb'
@exclude_pattern = ''
Expand Down Expand Up @@ -803,20 +787,6 @@ def full_backtrace=(true_or_false)
@backtrace_formatter.full_backtrace = true_or_false
end

# Enables color output if the output is a TTY. As of RSpec 3.6, this is
# the default behavior and this option is retained only for backwards
# compatibility.
#
# @deprecated No longer recommended because of complex behavior. Instead,
# rely on the fact that TTYs will display color by default, or set
# {#color_mode} to :on to display color on a non-TTY output.
# @see color_mode
# @see color_enabled?
# @return [Boolean]
def color
value_for(:color) { @color }
end

# The mode for determining whether to display output in color. One of:
#
# - :automatic - the output will be in color if the output is a TTY (the
Expand All @@ -839,20 +809,13 @@ def color_enabled?(output=output_stream)
when :on then true
when :off then false
else # automatic
output_to_tty?(output) || (color && tty?)
output_to_tty?(output)
end
end

# Set the color mode.
attr_writer :color_mode

# Toggle output color.
#
# @deprecated No longer recommended because of complex behavior. Instead,
# rely on the fact that TTYs will display color by default, or set
# {:color_mode} to :on to display color on a non-TTY output.
attr_writer :color

# @private
def libs=(libs)
libs.map do |lib|
Expand Down Expand Up @@ -1101,8 +1064,8 @@ def alias_example_group_to(new_name, *args)
RSpec::Core::ExampleGroup.define_example_group_method(new_name, extra_options)
end

# Define an alias for it_should_behave_like that allows different
# language (like "it_has_behavior" or "it_behaves_like") to be
# Define an alias for it_behaves_like that allows different
# language (like "it_has_behavior" or "it_is_able_to") to be
# employed when including shared examples.
#
# @example
Expand All @@ -1124,13 +1087,10 @@ def alias_example_group_to(new_name, *args)
# # ...sortability examples here
#
# @note Use with caution. This extends the language used in your
# specs, but does not add any additional documentation. We use this
# in RSpec to define `it_should_behave_like` (for backward
# compatibility), but we also add docs for that method.
# specs, but does not add any additional documentation.
def alias_it_behaves_like_to(new_name, report_label='')
RSpec::Core::ExampleGroup.define_nested_shared_group_method(new_name, report_label)
end
alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to

# Adds key/value pairs to the `inclusion_filter`. If `args`
# includes any symbols that are not part of the hash, each symbol
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/configuration_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def organize_options

UNFORCED_OPTIONS = Set.new([
:requires, :profile, :drb, :libs, :files_or_directories_to_run,
:full_description, :full_backtrace, :tty
:full_description, :full_backtrace
])

UNPROCESSABLE_OPTIONS = Set.new([:formatters])
Expand Down
2 changes: 0 additions & 2 deletions lib/rspec/core/drb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ def initialize(submitted_options, filter_manager)

def options
argv = []
argv << "--color" if @submitted_options[:color]
argv << "--force-color" if @submitted_options[:color_mode] == :on
argv << "--no-color" if @submitted_options[:color_mode] == :off
argv << "--profile" if @submitted_options[:profile_examples]
argv << "--backtrace" if @submitted_options[:full_backtrace]
argv << "--tty" if @submitted_options[:tty]
argv << "--fail-fast" if @submitted_options[:fail_fast]
argv << "--options" << @submitted_options[:custom_options_file] if @submitted_options[:custom_options_file]
argv << "--order" << @submitted_options[:order] if @submitted_options[:order]
Expand Down
9 changes: 0 additions & 9 deletions lib/rspec/core/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ def location_rerun_argument
end
end

# Returns the location-based argument that can be passed to the `rspec` command to rerun this example.
#
# @deprecated Use {#location_rerun_argument} instead.
# @note If there are multiple examples identified by this location, they will use {#id}
# to rerun instead, but this method will still return the location (that's why it is deprecated!).
def rerun_argument
location_rerun_argument
end

# @return [String] the unique id of this example. Pass
# this at the command line to re-run this exact example.
def id
Expand Down
7 changes: 2 additions & 5 deletions lib/rspec/core/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def self.define_example_group_method(name, metadata={})
# @!scope class
#
# @see SharedExampleGroup
def self.define_nested_shared_group_method(new_name, report_label="it should behave like")
def self.define_nested_shared_group_method(new_name, report_label="behaves like")
idempotently_define_singleton_method(new_name) do |name, *args, &customization_block|
# Pass :caller so the :location metadata is set properly.
# Otherwise, it'll be set to the next line because that's
Expand All @@ -329,10 +329,7 @@ def self.define_nested_shared_group_method(new_name, report_label="it should beh

# Generates a nested example group and includes the shared content
# mapped to `name` in the nested group.
define_nested_shared_group_method :it_behaves_like, "behaves like"
# Generates a nested example group and includes the shared content
# mapped to `name` in the nested group.
define_nested_shared_group_method :it_should_behave_like
define_nested_shared_group_method :it_behaves_like

# Includes shared content mapped to `name` directly in the group in which
# it is declared, as opposed to `it_behaves_like`, which creates a nested
Expand Down
10 changes: 3 additions & 7 deletions lib/rspec/core/formatters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,15 @@ def add(formatter_to_use, *paths)
formatter = RSpec::LegacyFormatters.load_formatter formatter_class, *args
register formatter, formatter.notifications
else
call_site = "Formatter added at: #{::RSpec::CallerFilter.first_non_rspec_line}"

RSpec.warn_deprecation <<-WARNING.gsub(/\s*\|/, ' ')
raise ArgumentError, <<-ERROR.gsub(/\s*\|/, ' ')
|The #{formatter_class} formatter uses the deprecated formatter
|interface not supported directly by RSpec 3.
|interface not supported directly by RSpec 4.
pirj marked this conversation as resolved.
Show resolved Hide resolved
|
|To continue to use this formatter you must install the
|`rspec-legacy_formatters` gem, which provides support
|for legacy formatters or upgrade the formatter to a
|compatible version.
|
|#{call_site}
WARNING
ERROR
end
end

Expand Down
33 changes: 2 additions & 31 deletions lib/rspec/core/mocking_adapters/mocha.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
# In order to support all versions of mocha, we have to jump through some
# hoops here.
#
# mocha >= '0.13.0':
# require 'mocha/api' is required.
# require 'mocha/object' raises a LoadError b/c the file no longer exists.
# mocha < '0.13.0', >= '0.9.7'
# require 'mocha/api' is required.
# require 'mocha/object' is required.
# mocha < '0.9.7':
# require 'mocha/api' raises a LoadError b/c the file does not yet exist.
# require 'mocha/standalone' is required.
# require 'mocha/object' is required.
begin
require 'mocha/api'

begin
require 'mocha/object'
rescue LoadError
# Mocha >= 0.13.0 no longer contains this file nor needs it to be loaded.
end
rescue LoadError
require 'mocha/standalone'
require 'mocha/object'
end
require 'mocha/api'

module RSpec
module Core
Expand All @@ -33,12 +9,7 @@ def self.framework_name
:mocha
end

# Mocha::Standalone was deprecated as of Mocha 0.9.7.
begin
include ::Mocha::API
rescue NameError
include ::Mocha::Standalone
end
include ::Mocha::API

def setup_mocks_for_rspec
mocha_setup
Expand Down
18 changes: 2 additions & 16 deletions lib/rspec/core/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,9 @@ def self.for(example)
execution_result = example.execution_result

return SkippedExampleNotification.new(example) if execution_result.example_skipped?
return new(example) unless execution_result.status == :pending || execution_result.status == :failed
return FailedExampleNotification.new(example) if execution_result.status == :pending || execution_result.status == :failed

klass = if execution_result.pending_fixed?
PendingExampleFixedNotification
elsif execution_result.status == :pending
PendingExampleFailedAsExpectedNotification
else
FailedExampleNotification
end

klass.new(example)
new(example)
end

private_class_method :new
Expand Down Expand Up @@ -214,12 +206,6 @@ def initialize(example, exception_presenter=Formatters::ExceptionPresenter::Fact
end
end

# @deprecated Use {FailedExampleNotification} instead.
class PendingExampleFixedNotification < FailedExampleNotification; end

# @deprecated Use {FailedExampleNotification} instead.
class PendingExampleFailedAsExpectedNotification < FailedExampleNotification; end

# The `SkippedExampleNotification` extends `ExampleNotification` with
# things useful for specs that are skipped.
#
Expand Down
8 changes: 1 addition & 7 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def parse(source=nil)
return { :files_or_directories_to_run => [] } if original_args.empty?
args = original_args.dup

options = args.delete('--tty') ? { :tty => true } : {}
options = {}
begin
parser(options).parse!(args)
rescue OptionParser::InvalidOption => e
Expand Down Expand Up @@ -140,12 +140,6 @@ def parser(options)
options[:full_backtrace] = true
end

parser.on('-c', '--color', '--colour', '') do |_o|
# flag will be excluded from `--help` output because it is deprecated
options[:color] = true
options[:color_mode] = :automatic
end

parser.on('--force-color', '--force-colour', 'Force the output to be in color, even if the output is not a TTY') do |_o|
if options[:color_mode] == :off
abort "Please only use one of `--force-color` and `--no-color`"
Expand Down