diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d4145ba7..1e0cecaa8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,6 @@ workflows: matrix: parameters: docker-image: - - mudge/re2-ci:1.8 - ruby:1.9 - ruby:2.0 - ruby:2.1 diff --git a/.rubocop.yml b/.rubocop.yml index 0d607d730..28074a966 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 '>= 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. diff --git a/Gemfile b/Gemfile index f0b516ed6..e06663915 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Rakefile b/Rakefile index bbcea3b51..48abe5c24 100644 --- a/Rakefile +++ b/Rakefile @@ -18,15 +18,10 @@ 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 @@ -34,11 +29,7 @@ namespace 'test' do # rubocop:disable Metrics/BlockLength 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 diff --git a/gemfiles/Gemfile.test-unit.latest b/gemfiles/Gemfile.test-unit.latest index 5600f62e7..265ea8895 100644 --- a/gemfiles/Gemfile.test-unit.latest +++ b/gemfiles/Gemfile.test-unit.latest @@ -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 diff --git a/lib/mocha.rb b/lib/mocha.rb index 06546e74f..0b6ab2dc1 100644 --- a/lib/mocha.rb +++ b/lib/mocha.rb @@ -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 diff --git a/lib/mocha/any_instance_method.rb b/lib/mocha/any_instance_method.rb index 8b128ea99..a821200a1 100644 --- a/lib/mocha/any_instance_method.rb +++ b/lib/mocha/any_instance_method.rb @@ -1,4 +1,3 @@ -require 'mocha/ruby_version' require 'mocha/stubbed_method' module Mocha diff --git a/lib/mocha/instance_method.rb b/lib/mocha/instance_method.rb index 86909ebe1..37c7f0501 100644 --- a/lib/mocha/instance_method.rb +++ b/lib/mocha/instance_method.rb @@ -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) diff --git a/lib/mocha/integration/test_unit.rb b/lib/mocha/integration/test_unit.rb index a3fc846e4..cd7791eb7 100644 --- a/lib/mocha/integration/test_unit.rb +++ b/lib/mocha/integration/test_unit.rb @@ -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' @@ -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) } diff --git a/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb b/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb deleted file mode 100644 index cd2a1241d..000000000 --- a/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'mocha/integration/assertion_counter' -require 'mocha/integration/monkey_patcher' -require 'mocha/expectation_error' - -module Mocha - module Integration - module TestUnit - module RubyVersion185AndBelow - def self.applicable_to?(test_unit_version, ruby_version) - Gem::Requirement.new('<= 1.2.3').satisfied_by?(test_unit_version) && Gem::Requirement.new('<= 1.8.5').satisfied_by?(ruby_version) - end - - def self.description - 'monkey patch for standard library in Ruby <= v1.8.5' - end - - def self.included(mod) - MonkeyPatcher.apply(mod, RunMethodPatch) - end - - module RunMethodPatch - # rubocop:disable all - def run(result) - assertion_counter = AssertionCounter.new(self) - yield(Test::Unit::TestCase::STARTED, name) - @_result = result - begin - begin - mocha_setup - setup - __send__(@method_name) - mocha_verify(assertion_counter) - rescue Mocha::ExpectationError => e - add_failure(e.message, e.backtrace) - rescue Test::Unit::AssertionFailedError => e - add_failure(e.message, e.backtrace) - rescue StandardError, ScriptError - add_error($!) - ensure - begin - teardown - rescue Mocha::ExpectationError => e - add_failure(e.message, e.backtrace) - rescue Test::Unit::AssertionFailedError => e - add_failure(e.message, e.backtrace) - rescue StandardError, ScriptError - add_error($!) - end - end - ensure - mocha_teardown - end - result.add_run - yield(Test::Unit::TestCase::FINISHED, name) - end - # rubocop:enable all - end - end - end - end -end diff --git a/lib/mocha/mock.rb b/lib/mocha/mock.rb index e5d96ca27..ea9f05e18 100644 --- a/lib/mocha/mock.rb +++ b/lib/mocha/mock.rb @@ -1,4 +1,3 @@ -require 'mocha/singleton_class' require 'mocha/expectation' require 'mocha/expectation_list' require 'mocha/invocation' @@ -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. @@ -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) diff --git a/lib/mocha/mockery.rb b/lib/mocha/mockery.rb index 64799c7d9..8aa0020bb 100644 --- a/lib/mocha/mockery.rb +++ b/lib/mocha/mockery.rb @@ -1,4 +1,3 @@ -require 'mocha/ruby_version' require 'mocha/central' require 'mocha/mock' require 'mocha/names' @@ -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)) diff --git a/lib/mocha/ruby_version.rb b/lib/mocha/ruby_version.rb index c5c672c5e..01a74d05b 100644 --- a/lib/mocha/ruby_version.rb +++ b/lib/mocha/ruby_version.rb @@ -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 diff --git a/lib/mocha/singleton_class.rb b/lib/mocha/singleton_class.rb deleted file mode 100644 index 607d464e5..000000000 --- a/lib/mocha/singleton_class.rb +++ /dev/null @@ -1,9 +0,0 @@ -if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9.2') - unless Kernel.method_defined?(:singleton_class) - module Kernel - def singleton_class - class << self; self; end - end - end - end -end diff --git a/lib/mocha/stubbed_method.rb b/lib/mocha/stubbed_method.rb index 48a1e17b1..95b64f5fa 100644 --- a/lib/mocha/stubbed_method.rb +++ b/lib/mocha/stubbed_method.rb @@ -1,5 +1,4 @@ require 'mocha/ruby_version' -require 'mocha/singleton_class' module Mocha class StubbedMethod @@ -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 diff --git a/mocha.gemspec b/mocha.gemspec index a155d9ae8..5d3caab8b 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 = '>= 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.' diff --git a/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb b/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb index e7f607502..2047d6cc6 100644 --- a/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +++ b/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb @@ -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 diff --git a/test/assertions.rb b/test/assertions.rb index daed7dabe..9d5f61e2d 100644 --- a/test/assertions.rb +++ b/test/assertions.rb @@ -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 diff --git a/test/method_definer.rb b/test/method_definer.rb index 1f5073946..bd0050a42 100644 --- a/test/method_definer.rb +++ b/test/method_definer.rb @@ -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) diff --git a/test/unit/any_instance_method_test.rb b/test/unit/any_instance_method_test.rb index 426afa27d..6f1cf6df0 100644 --- a/test/unit/any_instance_method_test.rb +++ b/test/unit/any_instance_method_test.rb @@ -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' @@ -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| diff --git a/test/unit/instance_method_test.rb b/test/unit/instance_method_test.rb index f903c09e0..0176c3130 100644 --- a/test/unit/instance_method_test.rb +++ b/test/unit/instance_method_test.rb @@ -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' @@ -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| diff --git a/test/unit/mock_test.rb b/test/unit/mock_test.rb index 36aa0e597..ac0dd8af7 100644 --- a/test/unit/mock_test.rb +++ b/test/unit/mock_test.rb @@ -1,5 +1,4 @@ require File.expand_path('../../test_helper', __FILE__) -require 'mocha/ruby_version' require 'mocha/macos_version' require 'mocha/mock' require 'mocha/expectation_error_factory' @@ -45,16 +44,10 @@ def test_should_be_equal assert_equal true, mock.eql?(mock) end - PRE_RUBY_V19_EXCLUDED_METHODS = %w[ - method_missing - singleton_method_undefined - initialize - ].freeze - MACOS_EXCLUDED_METHODS = MACOS && MACOS_VERSION >= MACOS_MOJAVE_VERSION ? [:syscall] : [] - RUBY_V19_AND_LATER_EXCLUDED_METHODS = [ + EXCLUDED_METHODS = [ :object_id, :method_missing, :singleton_method_undefined, @@ -65,9 +58,7 @@ def test_should_be_equal ].freeze OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject do |m| - (m =~ /^__.*__$/) || - (PRE_RUBY_V19 && PRE_RUBY_V19_EXCLUDED_METHODS.include?(m)) || - (!PRE_RUBY_V19 && RUBY_V19_AND_LATER_EXCLUDED_METHODS.include?(m)) + (m =~ /^__.*__$/) || EXCLUDED_METHODS.include?(m) end def test_should_be_able_to_mock_standard_object_methods @@ -350,12 +341,10 @@ def test_should_remove_expectations_for_unstubbed_methods assert_match(/unexpected invocation/, e.message) end - unless PRE_RUBY_V19 - def test_expectation_is_defined_on_mock - mock = build_mock - mock.expects(:method1) - assert defined? mock.method1 - end + def test_expectation_is_defined_on_mock + mock = build_mock + mock.expects(:method1) + assert defined? mock.method1 end private diff --git a/test/unit/object_inspect_test.rb b/test/unit/object_inspect_test.rb index 2abe90eb2..203fcfa67 100755 --- a/test/unit/object_inspect_test.rb +++ b/test/unit/object_inspect_test.rb @@ -1,5 +1,4 @@ require File.expand_path('../../test_helper', __FILE__) -require 'mocha/ruby_version' require 'mocha/inspect' require 'method_definer' @@ -27,12 +26,6 @@ class << object def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed calls = [] object = Object.new - if Mocha::PRE_RUBY_V19 - replace_instance_method(object, :id) do - calls << :id - return 1 - end - end replace_instance_method(object, :object_id) do calls << :object_id return 1