diff --git a/.yardopts b/.yardopts index 0a02817df..5543a4eec 100644 --- a/.yardopts +++ b/.yardopts @@ -16,7 +16,7 @@ lib/mocha/expectation_error.rb lib/mocha/stubbing_error.rb lib/mocha/unexpected_invocation.rb lib/mocha/integration/test_unit/adapter.rb -lib/mocha/integration/mini_test/adapter.rb +lib/mocha/integration/minitest/adapter.rb - RELEASE.md COPYING.md diff --git a/README.md b/README.md index 25c03bcba..f349cbdfd 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ * A Ruby library for [mocking](http://xunitpatterns.com/Mock%20Object.html) and [stubbing](http://xunitpatterns.com/Test%20Stub.html) - but deliberately not (yet) [faking](http://xunitpatterns.com/Fake%20Object.html) or [spying](http://xunitpatterns.com/Test%20Spy.html). * A unified, simple and readable syntax for both full & partial mocking. -* Built-in support for MiniTest and Test::Unit. +* Built-in support for Minitest and Test::Unit. * Supported by many other test frameworks. ### Intended Usage @@ -18,7 +18,7 @@ Install the latest version of the gem with the following command... $ gem install mocha -Note: If you are intending to use Mocha with Test::Unit or MiniTest, you should only setup Mocha *after* loading the relevant test library... +Note: If you are intending to use Mocha with Test::Unit or Minitest, you should only setup Mocha *after* loading the relevant test library... ##### Test::Unit @@ -29,12 +29,12 @@ require 'test/unit' require 'mocha/test_unit' ``` -##### MiniTest +##### Minitest ```ruby require 'rubygems' gem 'mocha' -require 'minitest/unit' +require 'minitest/autorun' require 'mocha/minitest' ``` @@ -53,14 +53,14 @@ require 'test/unit' require 'mocha/test_unit' ``` -##### MiniTest +##### Minitest ```ruby # Gemfile gem 'mocha' # Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'` -require 'minitest/unit' +require 'minitest/autorun' require 'mocha/minitest' ``` @@ -103,9 +103,9 @@ end If you're loading Mocha using Bundler within a Rails application, you should setup Mocha manually e.g. at the bottom of your `test_helper.rb`. -##### MiniTest +##### Minitest -Note that since Rails v4 (at least), `ActiveSupport::TestCase` has inherited from `Minitest::Test` or its earlier equivalents. Thus unless you are *explicitly* using Test::Unit, you are likely to be using MiniTest. +Note that since Rails v4 (at least), `ActiveSupport::TestCase` has inherited from `Minitest::Test` or its earlier equivalents. Thus unless you are *explicitly* using Test::Unit, you are likely to be using Minitest. ```ruby # Gemfile in Rails app diff --git a/Rakefile b/Rakefile index 1dd7509c6..04122ef22 100644 --- a/Rakefile +++ b/Rakefile @@ -42,10 +42,10 @@ namespace 'test' do # rubocop:disable Metrics/BlockLength end namespace 'integration' do - desc 'Run MiniTest integration tests (intended to be run in its own process)' + desc 'Run Minitest integration tests (intended to be run in its own process)' Rake::TestTask.new('minitest') do |t| t.libs << 'test' - t.test_files = FileList['test/integration/mini_test_test.rb'] + t.test_files = FileList['test/integration/minitest_test.rb'] t.verbose = true t.warning = true end @@ -93,18 +93,18 @@ end # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity def benchmark_test_case(klass, iterations) require 'benchmark' - require 'mocha/detection/mini_test' + require 'mocha/detection/minitest' - if defined?(MiniTest) - minitest_version = Gem::Version.new(Mocha::Detection::MiniTest.version) + if defined?(Minitest) + minitest_version = Gem::Version.new(Mocha::Detection::Minitest.version) if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version) Minitest.seed = 1 - result = Benchmark.realtime { iterations.times { |_i| klass.run(MiniTest::CompositeReporter.new) } } - MiniTest::Runnable.runnables.delete(klass) + result = Benchmark.realtime { iterations.times { |_i| klass.run(Minitest::CompositeReporter.new) } } + Minitest::Runnable.runnables.delete(klass) result else - MiniTest::Unit.output = StringIO.new - Benchmark.realtime { iterations.times { |_i| MiniTest::Unit.new.run([klass]) } } + Minitest::Unit.output = StringIO.new + Benchmark.realtime { iterations.times { |_i| Minitest::Unit.new.run([klass]) } } end else load 'test/unit/ui/console/testrunner.rb' unless defined?(Test::Unit::UI::Console::TestRunner) diff --git a/lib/mocha/api.rb b/lib/mocha/api.rb index f9841532c..b5a0518d1 100644 --- a/lib/mocha/api.rb +++ b/lib/mocha/api.rb @@ -7,7 +7,7 @@ require 'mocha/class_methods' module Mocha - # Methods added to +Test::Unit::TestCase+, +MiniTest::Unit::TestCase+ or equivalent. + # Methods added to +Test::Unit::TestCase+, +Minitest::Unit::TestCase+ or equivalent. # The mock creation methods are {#mock}, {#stub} and {#stub_everything}, all of which return a #{Mock} # which can be further modified by {Mock#responds_like} and {Mock#responds_like_instance_of} methods, # both of which return a {Mock}, too, and can therefore, be chained to the original creation methods. diff --git a/lib/mocha/detection/mini_test.rb b/lib/mocha/detection/minitest.rb similarity index 62% rename from lib/mocha/detection/mini_test.rb rename to lib/mocha/detection/minitest.rb index b9aebf079..4b1182208 100644 --- a/lib/mocha/detection/mini_test.rb +++ b/lib/mocha/detection/minitest.rb @@ -1,17 +1,17 @@ module Mocha module Detection - module MiniTest + module Minitest def self.testcase if defined?(::Minitest::Test) ::Minitest::Test - elsif defined?(::MiniTest::Unit::TestCase) - ::MiniTest::Unit::TestCase + elsif defined?(::Minitest::Unit::TestCase) + ::Minitest::Unit::TestCase end end def self.version - if defined?(::MiniTest::Unit::VERSION) - ::MiniTest::Unit::VERSION + if defined?(::Minitest::Unit::VERSION) + ::Minitest::Unit::VERSION elsif defined?(::Minitest::VERSION) ::Minitest::VERSION else diff --git a/lib/mocha/detection/test_unit.rb b/lib/mocha/detection/test_unit.rb index a5d097ab0..b7be2e41e 100644 --- a/lib/mocha/detection/test_unit.rb +++ b/lib/mocha/detection/test_unit.rb @@ -3,8 +3,8 @@ module Detection module TestUnit def self.testcase if defined?(::Test::Unit::TestCase) && - !(defined?(::MiniTest::Unit::TestCase) && (::Test::Unit::TestCase < ::MiniTest::Unit::TestCase)) && - !(defined?(::MiniTest::Spec) && (::Test::Unit::TestCase < ::MiniTest::Spec)) + !(defined?(::Minitest::Unit::TestCase) && (::Test::Unit::TestCase < ::Minitest::Unit::TestCase)) && + !(defined?(::Minitest::Spec) && (::Test::Unit::TestCase < ::Minitest::Spec)) ::Test::Unit::TestCase end end diff --git a/lib/mocha/expectation_error_factory.rb b/lib/mocha/expectation_error_factory.rb index 05b2e37be..6c15771a7 100644 --- a/lib/mocha/expectation_error_factory.rb +++ b/lib/mocha/expectation_error_factory.rb @@ -6,9 +6,9 @@ module Mocha # # This class should only be used by authors of test libraries and not by typical "users" of Mocha. # - # For example, it is used by +Mocha::Integration::MiniTest::Adapter+ in order to have Mocha raise a +MiniTest::Assertion+ which can then be sensibly handled by +MiniTest::Unit::TestCase+. + # For example, it is used by +Mocha::Integration::Minitest::Adapter+ in order to have Mocha raise a +Minitest::Assertion+ which can then be sensibly handled by +Minitest::Unit::TestCase+. # - # @see Mocha::Integration::MiniTest::Adapter + # @see Mocha::Integration::Minitest::Adapter class ExpectationErrorFactory class << self # @!attribute exception_class diff --git a/lib/mocha/hooks.rb b/lib/mocha/hooks.rb index 000c80fe6..cf19cf81e 100644 --- a/lib/mocha/hooks.rb +++ b/lib/mocha/hooks.rb @@ -7,12 +7,12 @@ module Mocha # # This module is provided as part of the +Mocha::API+ module and is therefore part of the public API, but should only be used by authors of test libraries and not by typical "users" of Mocha. # - # Integration with Test::Unit and MiniTest are provided as part of Mocha, because they are (or were once) part of the Ruby standard library. Integration with other test libraries is not provided as *part* of Mocha, but is supported by means of the methods in this module. + # Integration with Test::Unit and Minitest are provided as part of Mocha, because they are (or were once) part of the Ruby standard library. Integration with other test libraries is not provided as *part* of Mocha, but is supported by means of the methods in this module. # # See the code in the +Adapter+ modules for examples of how to use the methods in this module. +Mocha::ExpectationErrorFactory+ may be used if you want +Mocha+ to raise a different type of exception. # # @see Mocha::Integration::TestUnit::Adapter - # @see Mocha::Integration::MiniTest::Adapter + # @see Mocha::Integration::Minitest::Adapter # @see Mocha::ExpectationErrorFactory # @see Mocha::API module Hooks diff --git a/lib/mocha/integration/mini_test.rb b/lib/mocha/integration/mini_test.rb deleted file mode 100644 index 045307cac..000000000 --- a/lib/mocha/integration/mini_test.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'mocha/debug' -require 'mocha/detection/mini_test' -require 'mocha/integration/mini_test/adapter' - -module Mocha - module Integration - module MiniTest - def self.activate - target = Detection::MiniTest.testcase - return false unless target - - mini_test_version = Gem::Version.new(Detection::MiniTest.version) - Debug.puts "Detected MiniTest version: #{mini_test_version}" - - unless MiniTest::Adapter.applicable_to?(mini_test_version) - raise 'Versions of minitest earlier than v3.3.0 are not supported.' - end - - unless target < MiniTest::Adapter - Debug.puts "Applying #{MiniTest::Adapter.description}" - target.send(:include, MiniTest::Adapter) - end - - true - end - end - end -end diff --git a/lib/mocha/integration/minitest.rb b/lib/mocha/integration/minitest.rb new file mode 100644 index 000000000..1bd4b1a05 --- /dev/null +++ b/lib/mocha/integration/minitest.rb @@ -0,0 +1,28 @@ +require 'mocha/debug' +require 'mocha/detection/minitest' +require 'mocha/integration/minitest/adapter' + +module Mocha + module Integration + module Minitest + def self.activate + target = Detection::Minitest.testcase + return false unless target + + minitest_version = Gem::Version.new(Detection::Minitest.version) + Debug.puts "Detected Minitest version: #{minitest_version}" + + unless Minitest::Adapter.applicable_to?(minitest_version) + raise 'Versions of minitest earlier than v3.3.0 are not supported.' + end + + unless target < Minitest::Adapter + Debug.puts "Applying #{Minitest::Adapter.description}" + target.send(:include, Minitest::Adapter) + end + + true + end + end + end +end diff --git a/lib/mocha/integration/mini_test/adapter.rb b/lib/mocha/integration/minitest/adapter.rb similarity index 79% rename from lib/mocha/integration/mini_test/adapter.rb rename to lib/mocha/integration/minitest/adapter.rb index fd89551ce..0efbc7ee4 100644 --- a/lib/mocha/integration/mini_test/adapter.rb +++ b/lib/mocha/integration/minitest/adapter.rb @@ -4,21 +4,21 @@ module Mocha module Integration - module MiniTest - # Integrates Mocha into recent versions of MiniTest. + module Minitest + # Integrates Mocha into recent versions of Minitest. # # See the source code for an example of how to integrate Mocha into a test library. module Adapter include Mocha::API # @private - def self.applicable_to?(mini_test_version) - Gem::Requirement.new('>= 3.3.0').satisfied_by?(mini_test_version) + def self.applicable_to?(minitest_version) + Gem::Requirement.new('>= 3.3.0').satisfied_by?(minitest_version) end # @private def self.description - 'adapter for MiniTest gem >= v3.3.0' + 'adapter for Minitest gem >= v3.3.0' end # @private diff --git a/lib/mocha/integration/mini_test/exception_translation.rb b/lib/mocha/integration/minitest/exception_translation.rb similarity index 78% rename from lib/mocha/integration/mini_test/exception_translation.rb rename to lib/mocha/integration/minitest/exception_translation.rb index 9b18ff338..2c48ac7cd 100644 --- a/lib/mocha/integration/mini_test/exception_translation.rb +++ b/lib/mocha/integration/minitest/exception_translation.rb @@ -2,10 +2,10 @@ module Mocha module Integration - module MiniTest + module Minitest def self.translate(exception) return exception unless exception.is_a?(::Mocha::ExpectationError) - translated_exception = ::MiniTest::Assertion.new(exception.message) + translated_exception = ::Minitest::Assertion.new(exception.message) translated_exception.set_backtrace(exception.backtrace) translated_exception end diff --git a/lib/mocha/minitest.rb b/lib/mocha/minitest.rb index 2930ea219..0f801c417 100644 --- a/lib/mocha/minitest.rb +++ b/lib/mocha/minitest.rb @@ -1,6 +1,6 @@ require 'mocha/ruby_version' -require 'mocha/integration/mini_test' +require 'mocha/integration/minitest' -unless Mocha::Integration::MiniTest.activate - raise "MiniTest must be loaded *before* `require 'mocha/minitest'`." +unless Mocha::Integration::Minitest.activate + raise "Minitest must be loaded *before* `require 'mocha/minitest'`." end diff --git a/test/acceptance/acceptance_test_helper.rb b/test/acceptance/acceptance_test_helper.rb index 6bdc99d80..058eb277f 100644 --- a/test/acceptance/acceptance_test_helper.rb +++ b/test/acceptance/acceptance_test_helper.rb @@ -4,7 +4,7 @@ require 'mocha/mockery' require 'introspection' -if Mocha::Detection::MiniTest.testcase && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit') +if Mocha::Detection::Minitest.testcase && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit') require 'mocha/minitest' else require 'mocha/test_unit' diff --git a/test/integration/mini_test_test.rb b/test/integration/minitest_test.rb similarity index 79% rename from test/integration/mini_test_test.rb rename to test/integration/minitest_test.rb index b95529768..80e56e141 100644 --- a/test/integration/mini_test_test.rb +++ b/test/integration/minitest_test.rb @@ -3,6 +3,6 @@ require 'mocha/minitest' require 'integration/shared_tests' -class MiniTestTest < Mocha::TestCase +class MinitestTest < Mocha::TestCase include SharedTests end diff --git a/test/mini_test_result.rb b/test/minitest_result_pre_v5.rb similarity index 89% rename from test/mini_test_result.rb rename to test/minitest_result_pre_v5.rb index 24ce6f5db..2e599d959 100644 --- a/test/mini_test_result.rb +++ b/test/minitest_result_pre_v5.rb @@ -1,8 +1,8 @@ require 'stringio' -require 'minitest/unit' +require 'mocha/detection/minitest' -class MiniTestResult - minitest_version = Gem::Version.new(::MiniTest::Unit::VERSION) +class MinitestResult + minitest_version = Gem::Version.new(Mocha::Detection::Minitest.version) if Gem::Requirement.new('<= 4.6.1').satisfied_by?(minitest_version) FAILURE_PATTERN = /(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n/m ERROR_PATTERN = /(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n/m @@ -75,11 +75,11 @@ def passed? end def failures - @runner.report.map { |puked| MiniTestResult.parse_failure(puked) }.compact + @runner.report.map { |puked| MinitestResult.parse_failure(puked) }.compact end def errors - @runner.report.map { |puked| MiniTestResult.parse_error(puked) }.compact + @runner.report.map { |puked| MinitestResult.parse_error(puked) }.compact end def failure_messages diff --git a/test/test_helper.rb b/test/test_helper.rb index fbcaddb6d..8002aba07 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,7 +8,7 @@ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers')) $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance')) -require 'mocha/detection/mini_test' +require 'mocha/detection/minitest' begin require 'minitest' @@ -16,20 +16,14 @@ rescue LoadError end # rubocop:enable Lint/HandleExceptions -begin - require 'minitest/unit' -# rubocop:disable Lint/HandleExceptions -rescue LoadError -end -# rubocop:enable Lint/HandleExceptions module Mocha; end -if (minitest_testcase = Mocha::Detection::MiniTest.testcase) && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit') +if (minitest_testcase = Mocha::Detection::Minitest.testcase) && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit') begin require 'minitest/autorun' rescue LoadError - MiniTest::Unit.autorun + Minitest::Unit.autorun end # rubocop:disable Style/ClassAndModuleChildren class Mocha::TestCase < minitest_testcase diff --git a/test/test_runner.rb b/test/test_runner.rb index 7c8462cb7..b2a6acd19 100644 --- a/test/test_runner.rb +++ b/test/test_runner.rb @@ -1,6 +1,6 @@ require 'assertions' -require 'mocha/detection/mini_test' +require 'mocha/detection/minitest' module TestRunner def run_as_test(&block) @@ -20,20 +20,20 @@ def run_as_tests(methods = {}) tests = methods.keys.select { |m| m.to_s[/^test/] }.map { |m| test_class.new(m) } - if Mocha::Detection::MiniTest.testcase && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit') - minitest_version = Gem::Version.new(Mocha::Detection::MiniTest.version) + if Mocha::Detection::Minitest.testcase && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit') + minitest_version = Gem::Version.new(Mocha::Detection::Minitest.version) if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version) require File.expand_path('../minitest_result', __FILE__) tests.each(&:run) Minitest::Runnable.runnables.delete(test_class) test_result = MinitestResult.new(tests) elsif Gem::Requirement.new('> 0.0.0', '< 5.0.0').satisfied_by?(minitest_version) - require File.expand_path('../mini_test_result', __FILE__) - runner = MiniTest::Unit.new + require File.expand_path('../minitest_result_pre_v5', __FILE__) + runner = Minitest::Unit.new tests.each do |test| test.run(runner) end - test_result = MiniTestResult.new(runner, tests) + test_result = MinitestResult.new(runner, tests) end else require File.expand_path('../test_unit_result', __FILE__)