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

Drop Ruby < 2.3 support #436

Merged
merged 39 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
75149f3
Simplify fork_supported?
pirj Nov 12, 2020
7c2c610
Simplify ripper_supported?
pirj Nov 12, 2020
2f3489e
Remove redundant jruby_9000?
pirj Nov 12, 2020
3842f17
Remove kw_args_supported?
pirj Nov 12, 2020
26ca803
Remove supports_rebinding_module_methods?
pirj Nov 12, 2020
514ce68
Remove required_kw_args_supported?
pirj Nov 12, 2020
87dca93
Always use require_relative
pirj Nov 12, 2020
8109750
Remove optional_and_splat_args_supported?
pirj Nov 12, 2020
ba17eca
Remove caller_locations_supported?
pirj Nov 12, 2020
a372762
Remove supports_exception_cause?
pirj Nov 12, 2020
67f560d
Remove unused module_refinement_supported?
pirj Nov 12, 2020
c6257e9
Remove JRuby arity check workaround
pirj Nov 12, 2020
2a9c58a
Remove 1.8.7-specific workaround
pirj Nov 12, 2020
cd8b41e
Remove JRuby in 1.8.7 compat mode workaround
pirj Nov 12, 2020
ad44a2e
Remove 1.9 Open3 workaround
pirj Nov 12, 2020
ffd4518
Remove module_prepends_supported?
pirj Nov 12, 2020
1d1270d
Remove String#encoding workarounds
pirj Nov 12, 2020
3496910
Remove Time#nsec workaround
pirj Nov 12, 2020
81e4713
Remove 1.9.2-specific workaround
pirj Nov 12, 2020
e91cc38
Simplify a macro definition
pirj Nov 12, 2020
7e36bd3
Update required Ruby version gemspec constraint
pirj Nov 12, 2020
e072219
Remove explicit gem version constraints
pirj Nov 12, 2020
9939949
Remove assorted older rubies workarounds
pirj Nov 12, 2020
b9c5674
Explicitly require ruby_features where needed
pirj Nov 12, 2020
69288f3
Remove const_defined? workaround
pirj Nov 12, 2020
1b2467f
Remove version-specific details from a doc
pirj Nov 12, 2020
b66b7c8
Remove old JRuby workaround
pirj Nov 12, 2020
571a692
Remove usages of jruby_9000
pirj Nov 12, 2020
0c3c74e
Remove non_mri?
pirj Nov 12, 2020
a92dc58
Add Changelog entry
pirj Nov 14, 2020
b69244f
Get rid of evals
pirj Nov 15, 2020
fdd801c
Fix offences
pirj Nov 15, 2020
d181a28
Use Mutex from core, prevent it from being stubbed
pirj Nov 18, 2020
dd56e6f
Remove StdErrSplitter workarounds
pirj Nov 18, 2020
38885cf
Remove redundant boilerplate
pirj Nov 22, 2020
a9ab522
Remove BasicObject checks
pirj Nov 23, 2020
048eedd
Remove filtering for unsupported rubies
pirj Dec 8, 2020
a787fa2
Fix code doc
pirj Dec 8, 2020
0d41dfa
Downgrade ffi due to their usage of Gem
pirj Dec 12, 2020
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
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,9 @@
### Development (unreleased)

Breaking Changes:

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

### 3.10.0 / 2020-10-30 ### 3.10.0 / 2020-10-30


No changes. Released to support other RSpec releases. No changes. Released to support other RSpec releases.
Expand Down
34 changes: 2 additions & 32 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,51 +13,21 @@ branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp
end end
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.3'
end

if ENV['DIFF_LCS_VERSION'] if ENV['DIFF_LCS_VERSION']
gem 'diff-lcs', ENV['DIFF_LCS_VERSION'] gem 'diff-lcs', ENV['DIFF_LCS_VERSION']
else else
gem 'diff-lcs', '~> 1.4', '>= 1.4.3' gem 'diff-lcs', '~> 1.4', '>= 1.4.3'
end end


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


### dep for ci/coverage ### dep for ci/coverage
gem 'simplecov', '~> 0.8' gem 'simplecov', '~> 0.8'


if RUBY_VERSION < '2.0.0' || RUBY_ENGINE == 'java'
gem 'json', '< 2.0.0' # is a dependency of simplecov
else
gem 'json', '> 2.3.0'
end

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'
# ffi dropped Ruby 1.8 support in 1.9.19 and Ruby 1.9 support in 1.11.0
gem 'ffi', '< 1.9.19'
elsif RUBY_VERSION < '2.3.0'
gem 'ffi', '~> 1.12.0'
else
gem 'ffi', '~> 1.13.0'
end

# No need to run rubocop on earlier versions # No need to run rubocop on earlier versions
if RUBY_VERSION >= '2.4' && RUBY_ENGINE == 'ruby' if RUBY_VERSION >= '2.4' && RUBY_ENGINE == 'ruby'
gem "rubocop", "~> 0.52.1" gem "rubocop", "~> 0.52.1"
end end


eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom') eval_gemfile 'Gemfile-custom' if File.exist?('Gemfile-custom')
29 changes: 1 addition & 28 deletions lib/rspec/support.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@ module Support
# hand, does a linear O(N) search over the dirs in the $LOAD_PATH until # hand, does a linear O(N) search over the dirs in the $LOAD_PATH until
# it can resolve the file relative to one of the dirs. # it can resolve the file relative to one of the dirs.
def self.define_optimized_require_for_rspec(lib, &require_relative) def self.define_optimized_require_for_rspec(lib, &require_relative)
name = "require_rspec_#{lib}" define_singleton_method("require_rspec_#{lib}") do |f|

if Kernel.respond_to?(:require_relative)
(class << self; self; end).__send__(:define_method, name) do |f|
require_relative.call("#{lib}/#{f}") require_relative.call("#{lib}/#{f}")
end end
else
(class << self; self; end).__send__(:define_method, name) do |f|
require "rspec/#{lib}/#{f}"
end
end
end end


define_optimized_require_for_rspec(:support) { |f| require_relative(f) } define_optimized_require_for_rspec(:support) { |f| require_relative(f) }
require_rspec_support "version" require_rspec_support "version"
require_rspec_support "ruby_features"


# @api private # @api private
KERNEL_METHOD_METHOD = ::Kernel.instance_method(:method) KERNEL_METHOD_METHOD = ::Kernel.instance_method(:method)
Expand All @@ -43,25 +34,8 @@ def self.define_optimized_require_for_rspec(lib, &require_relative)
# - BasicObject subclasses that mixin a Kernel dup (e.g. SimpleDelegator) # - BasicObject subclasses that mixin a Kernel dup (e.g. SimpleDelegator)
# - Objects that undefine method and delegate everything to another # - Objects that undefine method and delegate everything to another
# object (e.g. Mongoid association objects) # object (e.g. Mongoid association objects)
if RubyFeatures.supports_rebinding_module_methods?
def self.method_handle_for(object, method_name)
KERNEL_METHOD_METHOD.bind(object).call(method_name)
rescue NameError => original
begin
handle = object.method(method_name)
raise original unless handle.is_a? Method
handle
rescue Support::AllExceptionsExceptOnesWeMustNotRescue
raise original
end
end
else
def self.method_handle_for(object, method_name) def self.method_handle_for(object, method_name)
if ::Kernel === object
KERNEL_METHOD_METHOD.bind(object).call(method_name) KERNEL_METHOD_METHOD.bind(object).call(method_name)
else
object.method(method_name)
end
rescue NameError => original rescue NameError => original
begin begin
handle = object.method(method_name) handle = object.method(method_name)
Expand All @@ -71,7 +45,6 @@ def self.method_handle_for(object, method_name)
raise original raise original
end end
end end
end


# @api private # @api private
# #
Expand Down
10 changes: 0 additions & 10 deletions lib/rspec/support/caller_filter.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,3 @@
RSpec::Support.require_rspec_support "ruby_features"

module RSpec module RSpec
# Consistent implementation for "cleaning" the caller method to strip out # Consistent implementation for "cleaning" the caller method to strip out
# non-rspec lines. This enables errors to be reported at the call site in # non-rspec lines. This enables errors to be reported at the call site in
Expand Down Expand Up @@ -27,7 +25,6 @@ class CallerFilter
# with this complexity in our `RSpec.deprecate` calls, so we ignore it here. # with this complexity in our `RSpec.deprecate` calls, so we ignore it here.
IGNORE_REGEX = Regexp.union(LIB_REGEX, "rubygems/core_ext/kernel_require.rb") IGNORE_REGEX = Regexp.union(LIB_REGEX, "rubygems/core_ext/kernel_require.rb")


if RSpec::Support::RubyFeatures.caller_locations_supported?
# This supports args because it's more efficient when the caller specifies # This supports args because it's more efficient when the caller specifies
# these. It allows us to skip frames the caller knows are part of RSpec, # these. It allows us to skip frames the caller knows are part of RSpec,
# and to decrease the increment size if the caller is confident the line will # and to decrease the increment size if the caller is confident the line will
Expand Down Expand Up @@ -72,12 +69,5 @@ def self.first_non_rspec_line(skip_frames=3, increment=5)
increment *= 2 # The choice of two here is arbitrary. increment *= 2 # The choice of two here is arbitrary.
end end
end end
else
# Earlier rubies do not support the two argument form of `caller`. This
# fallback is logically the same, but slower.
def self.first_non_rspec_line(*)
caller.find { |line| line !~ IGNORE_REGEX }
end
end
end end
end end
6 changes: 0 additions & 6 deletions lib/rspec/support/differ.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -102,15 +102,9 @@ def diffably_stringify(array)
end end
end end


if String.method_defined?(:encoding)
def multiline?(string) def multiline?(string)
string.include?("\n".encode(string.encoding)) string.include?("\n".encode(string.encoding))
end end
else
def multiline?(string)
string.include?("\n")
end
end


def build_hunks(actual, expected) def build_hunks(actual, expected)
HunkGenerator.new(actual, expected).hunks HunkGenerator.new(actual, expected).hunks
Expand Down
2 changes: 0 additions & 2 deletions lib/rspec/support/directory_maker.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,3 @@
RSpec::Support.require_rspec_support 'ruby_features'

module RSpec module RSpec
module Support module Support
# @api private # @api private
Expand Down
55 changes: 9 additions & 46 deletions lib/rspec/support/encoded_string.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,5 @@
RSpec::Support.require_rspec_support "ruby_features"

module RSpec module RSpec
module Support module Support
# @private # @private
Expand Down Expand Up @@ -46,7 +48,9 @@ def to_s
end end
alias :to_str :to_s alias :to_str :to_s


if String.method_defined?(:encoding) def self.pick_encoding(source_a, source_b)
Encoding.compatible?(source_a, source_b) || Encoding.default_external
end


private private


Expand Down Expand Up @@ -95,16 +99,11 @@ def matching_encoding(string)
# Originally defined as a constant to avoid uneeded allocations, this hash must # Originally defined as a constant to avoid uneeded allocations, this hash must
# be defined inline (without {}) to avoid warnings on Ruby 2.7 # be defined inline (without {}) to avoid warnings on Ruby 2.7
# #
# In MRI 2.1 'invalid: :replace' changed to also replace an invalid byte sequence # 'invalid: :replace' also replaces an invalid byte sequence
# see https://github.com/ruby/ruby/blob/v2_1_0/NEWS#L176
# https://www.ruby-forum.com/topic/6861247
# https://twitter.com/nalsh/status/553413844685438976
#
# For example, given:
# "\x80".force_encoding("Emacs-Mule").encode(:invalid => :replace).bytes.to_a
# #
# On MRI 2.1 or above: 63 # '?' # For example:
# else : 128 # "\x80" # "\x80".force_encoding("Emacs-Mule").encode(:invalid => :replace).bytes.to_a # =>
# => 63 # '?'
# #
string.encode(@encoding, :invalid => :replace, :undef => :replace, :replace => REPLACE) string.encode(@encoding, :invalid => :replace, :undef => :replace, :replace => REPLACE)
rescue Encoding::ConverterNotFoundError rescue Encoding::ConverterNotFoundError
Expand All @@ -113,49 +112,13 @@ def matching_encoding(string)
string.dup.force_encoding(@encoding).encode(:invalid => :replace, :replace => REPLACE) string.dup.force_encoding(@encoding).encode(:invalid => :replace, :replace => REPLACE)
end end


# Prevents raising ArgumentError
if String.method_defined?(:scrub)
# https://github.com/ruby/ruby/blob/eeb05e8c11/doc/NEWS-2.1.0#L120-L123
# https://github.com/ruby/ruby/blob/v2_1_0/string.c#L8242
# https://github.com/hsbt/string-scrub
# https://github.com/rubinius/rubinius/blob/v2.5.2/kernel/common/string.rb#L1913-L1972
def remove_invalid_bytes(string) def remove_invalid_bytes(string)
string.scrub(REPLACE) string.scrub(REPLACE)
end end
else
# http://stackoverflow.com/a/8711118/879854
# Loop over chars in a string replacing chars
# with invalid encoding, which is a pretty good proxy
# for the invalid byte sequence that causes an ArgumentError
def remove_invalid_bytes(string)
string.chars.map do |char|
char.valid_encoding? ? char : REPLACE
end.join
end
end


def detect_source_encoding(string) def detect_source_encoding(string)
string.encoding string.encoding
end end

def self.pick_encoding(source_a, source_b)
Encoding.compatible?(source_a, source_b) || Encoding.default_external
end
else

def self.pick_encoding(_source_a, _source_b)
end

private

def matching_encoding(string)
string
end

def detect_source_encoding(_string)
US_ASCII
end
end
end end
end end
end end
3 changes: 1 addition & 2 deletions lib/rspec/support/fuzzy_matcher.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def self.values_match?(expected, actual)
begin begin
expected === actual expected === actual
rescue ArgumentError rescue ArgumentError
# Some objects, like 0-arg lambdas on 1.9+, raise # Some objects, like 0-arg lambdas, raise ArgumentError when compared with ===.
# ArgumentError for `expected === actual`.
false false
end end
end end
Expand Down
Loading