Skip to content

Commit

Permalink
Remove support for Ruby v1.8
Browse files Browse the repository at this point in the history
Extended maintenance of Ruby v1.8.7 ended on 31 Jul 2014 [1] and Mocha
support for Ruby v1.8 has been deprecated since v1.10 [2].

Recent work in #534 has run into problems with files containing keyword
arguments not being parsable by Ruby v1.8 and so I think the time has
come to drop support.

Note that I had to change a couple of hard-coded line numbers in unit
tests to match up with the changed source code in
lib/mocha/stubbed_method.rb.

[1]: https://www.ruby-lang.org/en/news/2014/07/01/eol-for-1-8-7-and-1-9-2/
[2]: c5f8496
  • Loading branch information
floehopper committed Aug 21, 2022
1 parent 1ade384 commit ddb5d67
Show file tree
Hide file tree
Showing 23 changed files with 43 additions and 175 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ workflows:
matrix:
parameters:
docker-image:
- mudge/re2-ci:1.8
- ruby:1.9
- ruby:2.0
- ruby:2.1
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 1.8.6'
TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 1.9'

# 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.
Expand Down
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ source 'https://rubygems.org'
gemspec

# rubocop:disable Bundler/DuplicatedGem
if RUBY_VERSION < '1.9.3'
gem 'rake', '~> 10.0'
elsif RUBY_VERSION < '2'
if RUBY_VERSION < '2'
gem 'rake', '~> 12.2.1'
elsif RUBY_VERSION < '2.2'
gem 'rake', '~> 12.3.3'
Expand Down
13 changes: 2 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,18 @@ task 'test' do
end

namespace 'test' do # rubocop:disable Metrics/BlockLength
unit_tests = FileList['test/unit/**/*_test.rb']
all_acceptance_tests = FileList['test/acceptance/*_test.rb']
ruby186_incompatible_acceptance_tests = FileList['test/acceptance/stub_class_method_defined_on_*_test.rb'] + FileList['test/acceptance/stub_instance_method_defined_on_*_test.rb']
ruby186_compatible_acceptance_tests = all_acceptance_tests - ruby186_incompatible_acceptance_tests

desc 'Run unit tests'
Rake::TestTask.new('units') do |t|
t.libs << 'test'
t.test_files = unit_tests
t.test_files = FileList['test/unit/**/*_test.rb']
t.verbose = true
t.warning = true
end

desc 'Run acceptance tests'
Rake::TestTask.new('acceptance') do |t|
t.libs << 'test'
t.test_files = if defined?(RUBY_VERSION) && (RUBY_VERSION >= '1.8.7')
all_acceptance_tests
else
ruby186_compatible_acceptance_tests
end
t.test_files = FileList['test/acceptance/*_test.rb']
t.verbose = true
t.warning = true
end
Expand Down
6 changes: 1 addition & 5 deletions gemfiles/Gemfile.test-unit.latest
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ gemspec :path=>"../"

group :development do
gem "rake"
if RUBY_VERSION < '1.9'
gem "test-unit", "~> 2"
else
gem "test-unit"
end
gem "test-unit"
end
8 changes: 0 additions & 8 deletions lib/mocha.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
require 'mocha/version'
require 'mocha/ruby_version'
require 'mocha/deprecation'

if Mocha::PRE_RUBY_V19
Mocha::Deprecation.warning(
'Versions of Ruby earlier than v1.9 will not be supported in future versions of Mocha.'
)
end
1 change: 0 additions & 1 deletion lib/mocha/any_instance_method.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'mocha/ruby_version'
require 'mocha/stubbed_method'

module Mocha
Expand Down
2 changes: 1 addition & 1 deletion lib/mocha/instance_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def mock_owner
end

def method_body(method)
PRE_RUBY_V19 ? proc { |*args, &block| method.call(*args, &block) } : method
method
end

def stubbee_method(method_name)
Expand Down
2 changes: 0 additions & 2 deletions lib/mocha/integration/test_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'mocha/detection/test_unit'

require 'mocha/integration/test_unit/nothing'
require 'mocha/integration/test_unit/ruby_version_185_and_below'
require 'mocha/integration/test_unit/ruby_version_186_and_above'
require 'mocha/integration/test_unit/gem_version_200'
require 'mocha/integration/test_unit/gem_version_201_to_202'
Expand Down Expand Up @@ -31,7 +30,6 @@ def self.activate
TestUnit::GemVersion201To202,
TestUnit::GemVersion200,
TestUnit::RubyVersion186AndAbove,
TestUnit::RubyVersion185AndBelow,
TestUnit::Nothing
].detect { |m| m.applicable_to?(test_unit_version, ruby_version) }

Expand Down
61 changes: 0 additions & 61 deletions lib/mocha/integration/test_unit/ruby_version_185_and_below.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/mocha/mock.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'mocha/singleton_class'
require 'mocha/expectation'
require 'mocha/expectation_list'
require 'mocha/invocation'
Expand All @@ -8,7 +7,6 @@
require 'mocha/parameters_matcher'
require 'mocha/argument_iterator'
require 'mocha/expectation_error_factory'
require 'mocha/ruby_version'

module Mocha
# Traditional mock object.
Expand Down Expand Up @@ -330,13 +328,6 @@ def respond_to_missing?(symbol, include_all)
end
end

if PRE_RUBY_V19
# @private
def respond_to?(symbol, include_all = false)
respond_to_missing?(symbol, include_all)
end
end

# @private
def __verified__?(assertion_counter = nil)
@expectations.verified?(assertion_counter)
Expand Down
3 changes: 1 addition & 2 deletions lib/mocha/mockery.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'mocha/ruby_version'
require 'mocha/central'
require 'mocha/mock'
require 'mocha/names'
Expand Down Expand Up @@ -119,7 +118,7 @@ def mocha_inspect
end

def on_stubbing(object, method)
method = PRE_RUBY_V19 ? method.to_s : method.to_sym
method = method.to_sym
signature_proc = lambda { "#{object.mocha_inspect}.#{method}" }
check(:stubbing_non_existent_method, 'non-existent method', signature_proc) do
!(object.stubba_class.__method_exists__?(method, true) || object.respond_to?(method.to_sym))
Expand Down
1 change: 0 additions & 1 deletion lib/mocha/ruby_version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
module Mocha
PRE_RUBY_V19 = Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9')
RUBY_V2_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2')
end
9 changes: 0 additions & 9 deletions lib/mocha/singleton_class.rb

This file was deleted.

3 changes: 1 addition & 2 deletions lib/mocha/stubbed_method.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'mocha/ruby_version'
require 'mocha/singleton_class'

module Mocha
class StubbedMethod
Expand All @@ -11,7 +10,7 @@ def initialize(stubbee, method_name)
@stubbee = stubbee
@original_method = nil
@original_visibility = nil
@method_name = PRE_RUBY_V19 ? method_name.to_s : method_name.to_sym
@method_name = method_name.to_sym
end

def stub
Expand Down
2 changes: 1 addition & 1 deletion mocha.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '>= 1.8.7'
s.required_ruby_version = '>= 1.9'

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.'
Expand Down
48 changes: 23 additions & 25 deletions test/acceptance/stub_method_defined_on_module_and_aliased_test.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
require File.expand_path('../acceptance_test_helper', __FILE__)

unless Mocha::PRE_RUBY_V19
class StubMethodDefinedOnModuleAndAliasedTest < Mocha::TestCase
include AcceptanceTest
class StubMethodDefinedOnModuleAndAliasedTest < Mocha::TestCase
include AcceptanceTest

def setup
setup_acceptance_test
end
def setup
setup_acceptance_test
end

def teardown
teardown_acceptance_test
end
def teardown
teardown_acceptance_test
end

def test_stubbing_class_method_defined_by_aliasing_module_instance_method
mod = Module.new do
def module_instance_method
'module-instance-method'
end
def test_stubbing_class_method_defined_by_aliasing_module_instance_method
mod = Module.new do
def module_instance_method
'module-instance-method'
end
end

klass = Class.new do
extend mod
class << self
alias_method :aliased_module_instance_method, :module_instance_method
end
klass = Class.new do
extend mod
class << self
alias_method :aliased_module_instance_method, :module_instance_method
end
end

assert_snapshot_unchanged(klass) do
test_result = run_as_test do
klass.stubs(:aliased_module_instance_method).returns('stubbed-aliased-module-instance-method')
assert_equal 'stubbed-aliased-module-instance-method', klass.aliased_module_instance_method
end
assert_passed(test_result)
assert_snapshot_unchanged(klass) do
test_result = run_as_test do
klass.stubs(:aliased_module_instance_method).returns('stubbed-aliased-module-instance-method')
assert_equal 'stubbed-aliased-module-instance-method', klass.aliased_module_instance_method
end
assert_passed(test_result)
end
end
end
4 changes: 1 addition & 3 deletions test/assertions.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'mocha/ruby_version'

module Assertions
def assert_method_visibility(object, method_name, visiblity)
method_key = Mocha::PRE_RUBY_V19 ? method_name.to_s : method_name.to_sym
method_key = method_name.to_sym
assert object.send("#{visiblity}_methods").include?(method_key), "#{method_name} is not #{visiblity}"
end
end
2 changes: 0 additions & 2 deletions test/method_definer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'mocha/singleton_class'

module MethodDefiner
def define_instance_method(object, method_symbol, &block)
object.singleton_class.send(:define_method, method_symbol, block)
Expand Down
3 changes: 2 additions & 1 deletion test/unit/any_instance_method_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.expand_path('../../test_helper', __FILE__)
require 'mocha/ruby_version'
require 'method_definer'
require 'mocha/class_methods'
require 'mocha/mock'
Expand Down Expand Up @@ -65,7 +66,7 @@ def test_should_include_the_filename_and_line_number_in_exceptions
method.define_new_method

expected_filename = 'stubbed_method.rb'
expected_line_number = 61
expected_line_number = 60

exception = assert_raises(Exception) { klass.new.method_x }
matching_line = exception.backtrace.find do |line|
Expand Down
4 changes: 2 additions & 2 deletions test/unit/instance_method_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require File.expand_path('../../test_helper', __FILE__)
require 'mocha/ruby_version'
require 'method_definer'
require 'mocha/class_methods'
require 'mocha/mock'
require 'mocha/singleton_class'

require 'mocha/instance_method'

Expand Down Expand Up @@ -70,7 +70,7 @@ def test_should_include_the_filename_and_line_number_in_exceptions
method.define_new_method

expected_filename = 'stubbed_method.rb'
expected_line_number = 61
expected_line_number = 60

exception = assert_raises(Exception) { klass.method_x }
matching_line = exception.backtrace.find do |line|
Expand Down
Loading

0 comments on commit ddb5d67

Please sign in to comment.