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

Drop Ruby < 2.3 #435

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a53ab85
Reduce Travis matrix
pirj Nov 12, 2020
13f7104
Bump MRI 2.7 to 2.7.2
pirj Nov 12, 2020
1f43f0f
Bump JRuby to 9.2
pirj Nov 12, 2020
70d85dc
Simplify update RubyGems script
pirj Nov 12, 2020
499c4c5
Simplify fork_supported?
pirj Nov 12, 2020
bc3f5de
Simplify ripper_supported?
pirj Nov 12, 2020
8554441
Remove redundant jruby_version
pirj Nov 12, 2020
7fb9297
Remove redundant jruby_9000?
pirj Nov 12, 2020
9c11344
Remove kw_args_supported?
pirj Nov 12, 2020
7784683
Remove supports_rebinding_module_methods?
pirj Nov 12, 2020
5941986
Remove required_kw_args_supported?
pirj Nov 12, 2020
963ac13
Always use require_relative
pirj Nov 12, 2020
c952c96
Remove optional_and_splat_args_supported?
pirj Nov 12, 2020
e757fd2
Remove caller_locations_supported?
pirj Nov 12, 2020
6754b48
Remove supports_exception_cause?
pirj Nov 12, 2020
eb44090
Remove unused module_refinement_supported?
pirj Nov 12, 2020
5887afd
Remove JRuby arity check workaround
pirj Nov 12, 2020
74530e8
Remove 1.8.7-specific workaround
pirj Nov 12, 2020
d1fab98
Remove JRuby in 1.8.7 compat mode workaround
pirj Nov 12, 2020
9582d42
Remove 1.9 Open3 workaround
pirj Nov 12, 2020
3bcc44c
Remove module_prepends_supported?
pirj Nov 12, 2020
47d6299
Remove String#encoding workarounds
pirj Nov 12, 2020
b0b2f80
Remove Time#nsec workaround
pirj Nov 12, 2020
a416c70
Remove 1.9.2-specific workaround
pirj Nov 12, 2020
877fe9d
Simplify a macro definition
pirj Nov 12, 2020
ed17177
Update required Ruby version gemspec constraint
pirj Nov 12, 2020
139b468
Bump version
pirj Nov 12, 2020
0291798
Remove explicit gem version constraints
pirj Nov 12, 2020
f017880
Remove warning ignores for unsupported rubies
pirj Nov 12, 2020
61d2acd
EXPERIMENTAL: Prototype rspec-dev changes
pirj Nov 12, 2020
a4833b4
Remove assorted older rubies workarounds
pirj Nov 12, 2020
2184664
Explicitly require ruby_features where needed
pirj Nov 12, 2020
beef835
Remove const_defined? workaround
pirj Nov 12, 2020
e42f72b
Remove version-specific details from a doc
pirj Nov 12, 2020
8bb78a7
Prefer Ruby core Mutex to our local copy
pirj Nov 12, 2020
ca82cc3
Remove Ruby < 2.3 from AppVeyor
pirj Nov 12, 2020
9ccb1c9
Remove old JRuby workaround
pirj Nov 12, 2020
a7737b4
Remove usages of jruby_9000
pirj Nov 12, 2020
ea6ada6
Remove non_mri?
pirj Nov 12, 2020
6e546c9
Retire 1.8-induced RuboCop settings
pirj Nov 12, 2020
213a999
TEMP: Update maintenance-branch to keep all changes in sync
pirj Nov 13, 2020
09ac883
TEMP: Don't clone rspec?
pirj Nov 13, 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
13 changes: 8 additions & 5 deletions .rubocop.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ Style/EvalWithLocation:
# eval is only used here to check syntax # eval is only used here to check syntax
- 'lib/rspec/support/ruby_features.rb' - 'lib/rspec/support/ruby_features.rb'


Lint/AssignmentInCondition:
Exclude:
# The pattern makes sense here
- 'lib/rspec/support/mutex.rb'

# Over time we'd like to get this down, but this is what we're at now. # Over time we'd like to get this down, but this is what we're at now.
Metrics/AbcSize: Metrics/AbcSize:
Max: 22 Max: 22


# Over time we'd like to get this down, but this is what we're at now. # Over time we'd like to get this down, but this is what we're at now.
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Max: 9 Max: 9

# TODO: turn on cops below sometimes later

Style/FrozenStringLiteralComment:
Enabled: false

Performance/UnfreezeString:
Enabled: false
21 changes: 0 additions & 21 deletions .rubocop_rspec_base.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,28 +39,12 @@ CyclomaticComplexity:
Documentation: Documentation:
Enabled: false Enabled: false


# We still support 1.8.7 which requires trailing dots
DotPosition:
EnforcedStyle: trailing

DoubleNegation: DoubleNegation:
Enabled: false Enabled: false


# each_with_object is unavailable on 1.8.7 so we have to disable this one.
EachWithObject:
Enabled: false

FormatString: FormatString:
EnforcedStyle: percent EnforcedStyle: percent


# As long as we support ruby 1.8.7 we have to use hash rockets.
HashSyntax:
EnforcedStyle: hash_rockets

# We can't use the new lambda syntax, since we still support 1.8.7.
Lambda:
Enabled: false

# Over time we'd like to get this down, but this is what we're at now. # Over time we'd like to get this down, but this is what we're at now.
LineLength: LineLength:
Max: 100 Max: 100
Expand Down Expand Up @@ -90,11 +74,6 @@ PercentLiteralDelimiters:
PredicateName: PredicateName:
Enabled: false Enabled: false


# On 1.8 `proc` is `lambda`, so we use `Proc.new` to ensure we get real procs on all supported versions.
# http://batsov.com/articles/2014/02/04/the-elements-of-style-in-ruby-number-12-proc-vs-proc-dot-new/
Proc:
Enabled: false

# Exceptions should be rescued with `Support::AllExceptionsExceptOnesWeMustNotRescue` # Exceptions should be rescued with `Support::AllExceptionsExceptOnesWeMustNotRescue`
RescueException: RescueException:
Enabled: true Enabled: true
Expand Down
17 changes: 4 additions & 13 deletions .travis.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,33 +15,24 @@ before_install:
bundler_args: "--binstubs --standalone --without documentation --path ../bundle" bundler_args: "--binstubs --standalone --without documentation --path ../bundle"
script: "script/run_build" script: "script/run_build"
rvm: rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- 2.0.0
- 2.1
- 2.2.10
- 2.3.8 - 2.3.8
- 2.4.10 - 2.4.10
- 2.5.8 - 2.5.8
- 2.6.6 - 2.6.6
- 2.7.1 - 2.7.2
- ruby-3.0.0-preview1 - ruby-3.0.0-preview1
- ruby-head - ruby-head
- ree - ree
- rbx-3 - rbx-3
- jruby-9.1.7.0 # pin JRuby to this until travis/rvm can install later versions - jruby-9.2
- jruby-head - jruby-head
- jruby-1.7
env: env:
- JRUBY_OPTS='--dev' - JRUBY_OPTS='--dev'
matrix: matrix:
include: include:
- rvm: jruby-1.7 - rvm: 2.7.2
env: JRUBY_OPTS='--dev --1.8'
- rvm: 2.7.1
env: DIFF_LCS_VERSION="~> 1.3.0" env: DIFF_LCS_VERSION="~> 1.3.0"
- rvm: 2.7.1 - rvm: 2.7.2
env: DIFF_LCS_VERSION="1.4.3" env: DIFF_LCS_VERSION="1.4.3"
allow_failures: allow_failures:
- rvm: jruby-head - rvm: jruby-head
Expand Down
32 changes: 2 additions & 30 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,49 +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.11.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'
else
gem 'ffi', '~> 1.11.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')
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ test_script:


environment: environment:
matrix: matrix:
- ruby_version: 200
- ruby_version: 21
- ruby_version: 22
- ruby_version: 23-x64 - ruby_version: 23-x64
- ruby_version: 24-x64 - ruby_version: 24-x64
- ruby_version: 25-x64 - ruby_version: 25-x64
Expand Down
33 changes: 3 additions & 30 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 All @@ -94,7 +67,7 @@ def self.failure_notifier=(callable)
end end


# @private # @private
DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure } DEFAULT_FAILURE_NOTIFIER = ->(failure, _opts) { raise failure }


# @api private # @api private
def self.failure_notifier def self.failure_notifier
Expand All @@ -121,7 +94,7 @@ class << self
end end


# @private # @private
DEFAULT_WARNING_NOTIFIER = lambda { |warning| ::Kernel.warn warning } DEFAULT_WARNING_NOTIFIER = ->(warning) { ::Kernel.warn warning }


# @api private # @api private
def self.warning_notifier def self.warning_notifier
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
47 changes: 1 addition & 46 deletions lib/rspec/support/comparable_version.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,46 +1 @@
module RSpec # FIXME: if you remove this, `double`, `hide_const`, `stub_const` can't be found in specs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯 🤷‍♂️

module Support
# @private
class ComparableVersion
include Comparable

attr_reader :string

def initialize(string)
@string = string
end

def <=>(other) # rubocop:disable Metrics/AbcSize
other = self.class.new(other) unless other.is_a?(self.class)

return 0 if string == other.string

longer_segment_count = [self, other].map { |version| version.segments.count }.max

longer_segment_count.times do |index|
self_segment = segments[index] || 0
other_segment = other.segments[index] || 0

if self_segment.class == other_segment.class
result = self_segment <=> other_segment
return result unless result == 0
else
return self_segment.is_a?(String) ? -1 : 1
end
end

0
end

def segments
@segments ||= string.scan(/[a-z]+|\d+/i).map do |segment|
if segment =~ /\A\d+\z/
segment.to_i
else
segment
end
end
end
end
end
end
10 changes: 2 additions & 8 deletions lib/rspec/support/differ.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def color?


def initialize(opts={}) def initialize(opts={})
@color = opts.fetch(:color, false) @color = opts.fetch(:color, false)
@object_preparer = opts.fetch(:object_preparer, lambda { |string| string }) @object_preparer = opts.fetch(:object_preparer, ->(string) { string })
end end


private private
Expand Down 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 Expand Up @@ -183,7 +177,7 @@ def object_to_string(object)
when Array when Array
PP.pp(ObjectFormatter.prepare_for_inspection(object), "".dup) PP.pp(ObjectFormatter.prepare_for_inspection(object), "".dup)
when String when String
object =~ /\n/ ? object : object.inspect object.match?(/\n/) ? object : object.inspect
else else
PP.pp(object, "".dup) PP.pp(object, "".dup)
end end
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
Loading