Repository: freerange/mocha (Ruby)

Issue:
Drop support for Ruby v2.1
This version has been [EOL since 31 Mar 2017](https://www.ruby-lang.org/en/downloads/branches/), i.e. nearly 8 years ago.



Fix (patch):
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 1b3e995a6..0fcd7d80f 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -70,7 +70,6 @@ workflows:
           matrix:
             parameters:
               docker-image:
-                - ruby:2.1
                 - ruby:2.2
                 - ruby:2.3
                 - ruby:2.4
diff --git a/.rubocop.yml b/.rubocop.yml
index f7d64c325..5203aa98c 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,7 +1,7 @@
 inherit_from: .rubocop_todo.yml
 
 AllCops:
-  TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 2.1'
+  TargetRubyVersion: 2.2
 
 # Even the reference in the documentation suggests that you should prefer
 # `alias_method` vs `alias`, so I don't understand why that isn't the default.
diff --git a/Gemfile b/Gemfile
index e227f21ea..ac6387e4e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,29 +2,17 @@ source 'https://rubygems.org'
 
 gemspec
 
-# rubocop:disable Bundler/DuplicatedGem
-if RUBY_VERSION < '2.2'
-  gem 'rake', '~> 12.3.3'
-else
-  gem 'rake'
-end
-# rubocop:enable Bundler/DuplicatedGem
-
 gem 'introspection', '~> 0.0.1'
+gem 'jaro_winkler', '>= 1.5.5'
+gem 'minitest'
+gem 'rake'
+gem 'rubocop', '> 0.56', '<= 0.58.2'
 
 # Avoid breaking change in psych v4 (https://bugs.ruby-lang.org/issues/17866)
 if RUBY_VERSION >= '3.1.0'
   gem 'psych', '< 4'
 end
 
-if RUBY_VERSION >= '2.2.0'
-  # No test libraries in standard library
-  gem 'minitest'
-end
-if RUBY_VERSION >= '2.2.0'
-  gem 'jaro_winkler', '>= 1.5.5'
-  gem 'rubocop', '> 0.56', '<= 0.58.2'
-end
 if RUBY_ENGINE == 'jruby'
   # Workaround for https://github.com/jruby/jruby/issues/8488
   gem 'jar-dependencies', '~> 0.4.1'
diff --git a/Rakefile b/Rakefile
index 04122ef22..b9ba8778f 100644
--- a/Rakefile
+++ b/Rakefile
@@ -6,7 +6,7 @@ require 'bundler/setup'
 
 require 'rake/testtask'
 begin
-  # Only available with default Gemfile and in Ruby >= v2.2
+  # Only available with default Gemfile
   require 'rubocop/rake_task'
 rescue LoadError # rubocop:disable Lint/HandleExceptions
 end
diff --git a/lib/mocha/configuration.rb b/lib/mocha/configuration.rb
index 2f4405bbb..a6a12cc43 100644
--- a/lib/mocha/configuration.rb
+++ b/lib/mocha/configuration.rb
@@ -14,7 +14,6 @@ module Mocha
   #   Mocha.configure do |c|
   #     c.stubbing_method_unnecessarily = :prevent
   #     c.stubbing_method_on_non_mock_object = :warn
-  #     c.stubbing_method_on_nil = :allow
   #   end
   #
   def self.configure
@@ -34,7 +33,6 @@ def self.configuration
   #   Mocha.configure do |c|
   #     c.stubbing_method_unnecessarily = :prevent
   #     c.stubbing_method_on_non_mock_object = :warn
-  #     c.stubbing_method_on_nil = :allow
   #   end
   #
   class Configuration
@@ -44,7 +42,6 @@ class Configuration
       stubbing_method_on_non_mock_object: :allow,
       stubbing_non_existent_method: :allow,
       stubbing_non_public_method: :allow,
-      stubbing_method_on_nil: :prevent,
       display_matching_invocations_on_failure: false,
       strict_keyword_argument_matching: false
     }.freeze
@@ -196,33 +193,6 @@ def stubbing_non_public_method
       @options[:stubbing_non_public_method]
     end
 
-    # Configure whether stubbing methods on the +nil+ object is allowed.
-    #
-    # This is usually done accidentally, but there might be rare cases where it is intended.
-    #
-    # This option only works for Ruby < v2.2.0. In later versions of Ruby +nil+ is frozen and so a {StubbingError} will be raised if you attempt to stub a method on +nil+.
-    #
-    # When +value+ is +:allow+, do nothing.
-    # When +value+ is +:warn+, display a warning.
-    # When +value+ is +:prevent+, raise a {StubbingError}. This is the default.
-    #
-    # @param [Symbol] value one of +:allow+, +:warn+, +:prevent+.
-    # @deprecated This method is deprecated and will be removed in a future release. +nil+ is frozen in Ruby >= v2.2 and Mocha will be dropping support for Ruby v2.1. At that point it won't be possible to stub methods on +nil+ any more.
-    #
-    def stubbing_method_on_nil=(value)
-      Deprecation.warning([
-        '`Mocha::Configuration#stubbing_method_on_nil=` is deprecated and will be removed in a future release.',
-        '`nil` is frozen in Ruby >= v2.2 and Mocha will be dropping support for Ruby v2.1.',
-        "At that point it won't be possible to stub methods on `nil` any more."
-      ].join(' '))
-      @options[:stubbing_method_on_nil] = value
-    end
-
-    # @private
-    def stubbing_method_on_nil
-      @options[:stubbing_method_on_nil]
-    end
-
     # Display matching invocations alongside expectations on Mocha-related test failure.
     #
     # @param [Boolean] value +true+ to enable display of matching invocations; disabled by default.
@@ -318,9 +288,9 @@ def reset_configuration
       # @param [Hash] temporary_options the configuration options to apply for the duration of the block.
       # @yield block during which the configuration change will be in force.
       #
-      # @example Temporarily allow stubbing of +nil+
-      #   Mocha::Configuration.override(stubbing_method_on_nil: :allow) do
-      #     nil.stubs(:foo)
+      # @example Temporarily prevent stubbing of non-mock object
+      #   Mocha::Configuration.override(stubbing_method_on_non_mock_object: :prevent) do
+      #     123.stubs(:to_s).returns('456')
       #   end
       def override(temporary_options)
         original_configuration = configuration
diff --git a/lib/mocha/mockery.rb b/lib/mocha/mockery.rb
index 92b956ece..12ffa6014 100644
--- a/lib/mocha/mockery.rb
+++ b/lib/mocha/mockery.rb
@@ -129,7 +129,6 @@ def on_stubbing(object, method)
       check(:stubbing_non_public_method, 'non-public method', signature_proc) do
         object.stubba_class.__method_exists__?(method, false)
       end
-      check(:stubbing_method_on_nil, 'method on nil', signature_proc) { object.nil? }
       check(:stubbing_method_on_non_mock_object, 'method on non-mock object', signature_proc)
     end
 
diff --git a/mocha.gemspec b/mocha.gemspec
index 13a3a476d..2e1de7a96 100644
--- a/mocha.gemspec
+++ b/mocha.gemspec
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
   s.name = 'mocha'
   s.version = Mocha::VERSION
   s.licenses = ['MIT', 'BSD-2-Clause']
-  s.required_ruby_version = '>= 2.1'
+  s.required_ruby_version = '>= 2.2'
 
   s.authors = ['James Mead']
   s.description = 'Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.'