Skip to content

Commit

Permalink
Use Minitest vs MiniTest everywhere
Browse files Browse the repository at this point in the history
All of these are either references to constants internal to Mocha or
documentation referencing the Minitest library.

As noted by @zenspider in this comment [1], the rename is over 10 years
old, so it seems about time we update it!

[1]: #614 (comment)
  • Loading branch information
floehopper committed Nov 12, 2023
1 parent 204639c commit 6328085
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 52 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -29,7 +29,7 @@ require 'test/unit'
require 'mocha/test_unit'
```

##### MiniTest
##### Minitest

```ruby
require 'rubygems'
Expand All @@ -53,7 +53,7 @@ require 'test/unit'
require 'mocha/test_unit'
```

##### MiniTest
##### Minitest

```ruby
# Gemfile
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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']
Expand Down Expand Up @@ -95,16 +95,16 @@ def benchmark_test_case(klass, iterations)
require 'benchmark'
require 'mocha/detection/mini_test'

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)
Expand Down
2 changes: 1 addition & 1 deletion lib/mocha/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions lib/mocha/detection/mini_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha/detection/test_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha/expectation_error_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/mocha/integration/mini_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

module Mocha
module Integration
module MiniTest
module Minitest
def self.activate
target = Detection::MiniTest.testcase
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}"
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)
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)
unless target < Minitest::Adapter
Debug.puts "Applying #{Minitest::Adapter.description}"
target.send(:include, Minitest::Adapter)
end

true
Expand Down
6 changes: 3 additions & 3 deletions lib/mocha/integration/mini_test/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

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
Expand All @@ -18,7 +18,7 @@ def self.applicable_to?(mini_test_version)

# @private
def self.description
'adapter for MiniTest gem >= v3.3.0'
'adapter for Minitest gem >= v3.3.0'
end

# @private
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha/integration/mini_test/exception_translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha/minitest.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'mocha/ruby_version'
require 'mocha/integration/mini_test'

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
2 changes: 1 addition & 1 deletion test/acceptance/acceptance_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/integration/mini_test_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
require 'mocha/minitest'
require 'integration/shared_tests'

class MiniTestTest < Mocha::TestCase
class MinitestTest < Mocha::TestCase
include SharedTests
end
8 changes: 4 additions & 4 deletions test/mini_test_result.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'stringio'

class MiniTestResult
minitest_version = Gem::Version.new(::MiniTest::VERSION)
class MinitestResult
minitest_version = Gem::Version.new(::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
Expand Down Expand Up @@ -74,11 +74,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
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

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
Expand Down
8 changes: 4 additions & 4 deletions test/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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__)
Expand Down

0 comments on commit 6328085

Please sign in to comment.