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

Drop Ruby < 2.3 support #2787

Merged
merged 19 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Development

Breaking Changes:

* Ruby < 2.3 is no longer supported. (Phil Pirozhkov, #2787)

Enhancements:

* Improve pluralisation of words ending with `s` (like process). (Joshua Pinter, #2779)
Expand Down
46 changes: 4 additions & 42 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp
end
end

if RUBY_VERSION < '1.9.3'
gem 'rake', '< 11.0.0' # rake 11 requires Ruby 1.9.3 or later
elsif RUBY_VERSION < '2.0.0'
gem 'rake', '< 12.0.0' # rake 12 requires Ruby 2.0.0 or later
else
gem 'rake', '> 12.3.2'
end

if ENV['DIFF_LCS_VERSION']
gem 'diff-lcs', ENV['DIFF_LCS_VERSION']
else
Expand All @@ -34,37 +26,10 @@ group :documentation do
gem 'github-markup', :platform => :mri
end

if RUBY_VERSION < '2.0.0' || RUBY_ENGINE == 'java'
gem 'json', '< 2.0.0'
else
gem 'json', '> 2.3.0'
end
# Until 1.13.2 is released due to Rubygems usage
gem 'ffi', '~> 1.12.0'

if RUBY_VERSION < '2.2.0' && !!(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
gem 'ffi', '< 1.10'
elsif RUBY_VERSION < '2.0'
gem 'ffi', '< 1.9.19' # ffi dropped Ruby 1.8 support in 1.9.19
elsif RUBY_VERSION < '2.3.0'
gem 'ffi', '~> 1.12.0'
else
# Until 1.13.2 is released due to Rubygems usage
gem 'ffi', '~> 1.12.0'
end

if RUBY_VERSION < '2.3.0' && !!(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
gem "childprocess", "< 1.0.0"
end

platforms :jruby do
if RUBY_VERSION < '1.9.0'
# Pin jruby-openssl on older J Ruby
gem "jruby-openssl", "< 0.10.0"
# Pin child-process on older J Ruby
gem "childprocess", "< 1.0.0"
else
gem "jruby-openssl"
end
end
gem "jruby-openssl", platforms: :jruby

gem 'simplecov', '~> 0.8'

Expand All @@ -73,14 +38,11 @@ if RUBY_VERSION >= '2.4' && RUBY_ENGINE == 'ruby'
gem "rubocop", "~> 0.52.1"
end

gem 'test-unit', '~> 3.0' if RUBY_VERSION.to_f >= 2.2
gem 'test-unit', '~> 3.0'

# Version 5.12 of minitest requires Ruby 2.4
if RUBY_VERSION < '2.4.0'
gem 'minitest', '< 5.12.0'
end


gem 'contracts', '< 0.16' if RUBY_VERSION < '1.9.0'

eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')
8 changes: 1 addition & 7 deletions Gemfile-custom.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ group :development do
platform :mri do
gem 'rb-fsevent', '~> 0.9.0'
gem 'ruby-prof', '~> 0.13.0'

case RUBY_VERSION
when /^1.8/
gem 'ruby-debug'
when /^1.9/
gem 'debugger'
end
gem 'pry-byebug'
end
end
6 changes: 1 addition & 5 deletions cucumber.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
<%
exclusions = []
exclusions << ' --tags ~@no-jruby' if RUBY_PLATFORM == 'java'
%>
default: --require features --strict --format progress --tags ~@wip<%= exclusions.join %> features
default: --require features --strict --format progress --tags ~@wip features
wip: --require features --tags @wip:30 --wip features
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ Feature: configure expectation framework
"""
And the output should contain "3 examples, 1 failure"

@broken-on-jruby-9000
Scenario: Configure minitest assertions
Given rspec-expectations is not installed
And a file named "example_spec.rb" with:
Expand Down
8 changes: 1 addition & 7 deletions features/step_definitions/additional_cli_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,7 @@

module Normalization
def normalize_failure_output(text)
whitespace_normalized = text.lines.map { |line| line.sub(/\s+$/, '').sub(/:in .*$/, '') }.join

# 1.8.7 and JRuby produce slightly different output for `Hash#fetch` errors, so we
# convert it to the same output here to match our expectation.
whitespace_normalized.
sub("IndexError", "KeyError").
sub(/key not found.*$/, "key not found")
text.lines.map { |line| line.sub(/\s+$/, '').sub(/:in .*$/, '') }.join
end
end

Expand Down
8 changes: 3 additions & 5 deletions features/step_definitions/core_standalone_steps.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
Given(/^only rspec-core is installed$/) do
if RUBY_VERSION.to_f >= 1.9 # --disable-gems is invalid on 1.8.7
# Ensure the gem versions of rspec-mocks and rspec-expectations
# won't be loaded if available on the developers machine.
set_environment_variable('RUBYOPT', ENV['RUBYOPT'] + ' --disable-gems')
end
# Ensure the gem versions of rspec-mocks and rspec-expectations
# won't be loaded if available on the developers machine.
set_environment_variable('RUBYOPT', ENV['RUBYOPT'] + ' --disable-gems')

# This will make `require_expect_syntax_in_aruba_specs.rb` (loaded
# automatically when the specs run) remove rspec-mocks and
Expand Down
4 changes: 0 additions & 4 deletions features/support/jruby.rb

This file was deleted.

6 changes: 2 additions & 4 deletions lib/rspec/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
warnings

set
flat_map
filter_manager
dsl
notifications
Expand Down Expand Up @@ -101,10 +100,9 @@ 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 all
# versions of RSpec 2 and 3.
# to the example currently being executed and also want to support RSpec 2.
#
# @example
# @example support for RSpec version 2
#
# RSpec.configure do |c|
# # context.example is deprecated, but RSpec.current_example is not
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/core/bisect/shell_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
RSpec::Support.require_rspec_core "shell_escape"
RSpec::Support.require_rspec_support 'ruby_features'
require 'shellwords'

module RSpec
Expand Down Expand Up @@ -63,6 +64,7 @@ def spec_opts_without_bisect
private

include RSpec::Core::ShellEscape

# On JRuby, Open3.popen3 does not handle shellescaped args properly:
# https://github.com/jruby/jruby/issues/2767
if RSpec::Support::Ruby.jruby?
Expand Down
27 changes: 2 additions & 25 deletions lib/rspec/core/bisect/shell_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,8 @@ def run_locations(*capture_args)
end
end

# `Open3.capture2e` does not work on JRuby:
# https://github.com/jruby/jruby/issues/2766
if Open3.respond_to?(:capture2e) && !RSpec::Support::Ruby.jruby?
def run_command(cmd)
Open3.capture2e(@shell_command.bisect_environment_hash, cmd).first
end
else # for 1.8.7
# :nocov:
def run_command(cmd)
out = err = nil

original_spec_opts = ENV['SPEC_OPTS']
ENV['SPEC_OPTS'] = @shell_command.spec_opts_without_bisect

Open3.popen3(cmd) do |_, stdout, stderr|
# Reading the streams blocks until the process is complete
out = stdout.read
err = stderr.read
end

"Stdout:\n#{out}\n\nStderr:\n#{err}"
ensure
ENV['SPEC_OPTS'] = original_spec_opts
end
# :nocov:
def run_command(cmd)
Open3.capture2e(@shell_command.bisect_environment_hash, cmd).first
end
end
end
Expand Down
111 changes: 48 additions & 63 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
RSpec::Support.require_rspec_core "ruby_project"
RSpec::Support.require_rspec_core "formatters/deprecation_formatter"
RSpec::Support.require_rspec_core "output_wrapper"
RSpec::Support.require_rspec_support 'ruby_features'

module RSpec
module Core
Expand Down Expand Up @@ -842,8 +843,8 @@ def expect_with(*frameworks)

# Tag this exception class so our exception formatting logic knows
# that it satisfies the `MultipleExceptionError` interface.
::RSpec::Expectations::MultipleExpectationsNotMetError.__send__(
:include, MultipleExceptionError::InterfaceTag
::RSpec::Expectations::MultipleExpectationsNotMetError.include(
MultipleExceptionError::InterfaceTag
)

::RSpec::Matchers
Expand Down Expand Up @@ -1495,43 +1496,41 @@ def extend(mod, *filters)
end
end

if RSpec::Support::RubyFeatures.module_prepends_supported?
# Tells RSpec to prepend example groups with `mod`. Methods defined in
# `mod` are exposed to examples (not example groups). Use `filters` to
# constrain the groups in which to prepend the module.
#
# Similar to `include`, but module is included before the example group's class
# in the ancestor chain.
#
# @example
#
# module OverrideMod
# def override_me
# "overridden"
# end
# end
#
# RSpec.configure do |config|
# config.prepend(OverrideMod, :method => :prepend)
# end
#
# describe "overriding example's class", :method => :prepend do
# it "finds the user" do
# self.class.class_eval do
# def override_me
# end
# end
# override_me # => "overridden"
# # ...
# end
# end
#
# @see #include
# @see #extend
def prepend(mod, *filters)
define_mixed_in_module(mod, filters, @prepend_modules, :prepend) do |group|
safe_prepend(mod, group)
end
# Tells RSpec to prepend example groups with `mod`. Methods defined in
# `mod` are exposed to examples (not example groups). Use `filters` to
# constrain the groups in which to prepend the module.
#
# Similar to `include`, but module is included before the example group's class
# in the ancestor chain.
#
# @example
#
# module OverrideMod
# def override_me
# "overridden"
# end
# end
#
# RSpec.configure do |config|
# config.prepend(OverrideMod, :method => :prepend)
# end
#
# describe "overriding example's class", :method => :prepend do
# it "finds the user" do
# self.class.class_eval do
# def override_me
# end
# end
# override_me # => "overridden"
# # ...
# end
# end
#
# @see #include
# @see #extend
def prepend(mod, *filters)
define_mixed_in_module(mod, filters, @prepend_modules, :prepend) do |group|
safe_prepend(mod, group)
end
end

Expand Down Expand Up @@ -1586,14 +1585,14 @@ def in_project_source_dir_regex

# @private
def configure_mock_framework
RSpec::Core::ExampleGroup.__send__(:include, mock_framework)
RSpec::Core::ExampleGroup.include(mock_framework)
conditionally_disable_mocks_monkey_patching
end

# @private
def configure_expectation_framework
expectation_frameworks.each do |framework|
RSpec::Core::ExampleGroup.__send__(:include, framework)
RSpec::Core::ExampleGroup.include(framework)
end
conditionally_disable_expectations_monkey_patching
end
Expand Down Expand Up @@ -2155,7 +2154,7 @@ def run_suite_hooks(hook_description, hooks)
end

def get_files_to_run(paths)
files = FlatMap.flat_map(paths_to_check(paths)) do |path|
files = paths_to_check(paths).flat_map do |path|
path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
File.directory?(path) ? gather_directories(path) : extract_location(path)
end.uniq
Expand Down Expand Up @@ -2331,30 +2330,16 @@ def metadata_applies_to_group?(meta, group)
meta.empty? || MetadataFilter.apply?(:any?, meta, group.metadata)
end

if RSpec::Support::RubyFeatures.module_prepends_supported?
def safe_prepend(mod, host)
host.__send__(:prepend, mod) unless host < mod
end
def safe_prepend(mod, host)
host.prepend(mod) unless host < mod
end

if RUBY_VERSION.to_f >= 1.9
def safe_include(mod, host)
host.__send__(:include, mod) unless host < mod
end

def safe_extend(mod, host)
host.extend(mod) unless host.singleton_class < mod
end
else # for 1.8.7
# :nocov:
def safe_include(mod, host)
host.__send__(:include, mod) unless host.included_modules.include?(mod)
end
def safe_include(mod, host)
host.include(mod) unless host < mod
end

def safe_extend(mod, host)
host.extend(mod) unless (class << host; self; end).included_modules.include?(mod)
end
# :nocov:
def safe_extend(mod, host)
host.extend(mod) unless host.singleton_class < mod
end

def define_mixed_in_module(mod, filters, mod_list, config_method, &block)
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 @@ -169,7 +169,7 @@ def parse_args_ignoring_files_or_dirs_to_run(args, source)
def args_from_options_file(path)
return [] unless path && File.exist?(path)
config_string = options_file_as_erb_string(path)
FlatMap.flat_map(config_string.split(/\n+/), &:shellsplit)
config_string.split(/\n+/).flat_map(&:shellsplit)
end

def options_file_as_erb_string(path)
Expand Down
4 changes: 3 additions & 1 deletion lib/rspec/core/example.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
RSpec::Support.require_rspec_support 'ruby_features'

module RSpec
module Core
# Wrapper for an instance of a subclass of {ExampleGroup}. An instance of
Expand Down Expand Up @@ -294,7 +296,7 @@ def run(example_group_instance, reporter)
RSpec.current_example = nil
end

if RSpec::Support::Ruby.jruby? || RUBY_VERSION.to_f < 1.9
if RSpec::Support::Ruby.jruby?
# :nocov:
# For some reason, rescuing `Support::AllExceptionsExceptOnesWeMustNotRescue`
# in place of `Exception` above can cause the exit status to be the wrong
Expand Down
Loading