Bug #9660

test/unit, minitest & bundler

Added by Marc-Andre Lafortune about 1 year ago. Updated 9 months ago.

[ruby-core:61623]
Status:Closed
Priority:High
Assignee:Shota Fukumori
ruby -v:r45033 Backport:2.0.0: DONTNEED, 2.1: DONTNEED

Description

test/unit now calls gem 'minitest', but this will create regressions for anyone using bundler.

For example, create an empty Gemfile and try bundle exec ruby -e "require 'test/unit'"

You get an error:

.rvm/gems/ruby-head@global/gems/bundler-1.5.3/lib/bundler/rubygems_integration.rb:240:in `block in replace_gem': minitest is not part of the bundle. Add it to Gemfile. (Gem::LoadError)

See: https://github.com/ruby/ruby/commit/da61291a25faae95f33de6756b2eaa4804d5ef2b#commitcomment-5761129


Related issues

Related to Ruby trunk - Feature #9711: Remove test-unit and minitest from stdlib. Closed 04/07/2014

History

#1 Updated by Shota Fukumori about 1 year ago

I guess this ugly patch fixes problem, but I want to find better solutions...

diff --git a/lib/test/unit.rb b/lib/test/unit.rb
index ccfe1ce..eb7545b 100644
--- a/lib/test/unit.rb
+++ b/lib/test/unit.rb
@@ -1,5 +1,25 @@
-gem 'minitest', '< 5.0.0' if defined? Gem
+if defined? Gem
+  begin
+    gem 'minitest', '< 5.0.0'
+  rescue Gem::LoadError # for bundler
+  end
+end
+
 require 'minitest/unit'
+
+if '5.0.0' <= MiniTest::Unit::VERSION
+  module Test
+    module Unit
+      class CompatibilityError < Exception
+      end
+    end
+  end
+
+  raise Test::Unit::CompatibilityError,
+    "test/unit only works on MiniTest 4 " \
+    "(MiniTest #{MiniTest::Unit::VERSION} loaded)"
+end
+
 require 'test/unit/assertions'
 require 'test/unit/testcase'
 require 'optparse'

#2 Updated by Hiroshi SHIBATA about 1 year ago

I think bundled test-unit should be rename like rbunit or ruby-unit. many of users is confused by bundled test-unit and test-unit gem.
If we can't merge their, it should be renamed.

#3 Updated by Zachary Scott about 1 year ago

I like the name ruby-unit, in this case we should also consider changing the namespaces to match (ie: RubyUnit)

#4 Updated by Eric Wong about 1 year ago

e@zzak.io wrote:

I like the name ruby-unit, in this case we should also consider
changing the namespaces to match (ie: RubyUnit)

Might as well use Minitest:: at that point, right?

#5 Updated by Eric Wong about 1 year ago

normalperson@yhbt.net wrote:

e@zzak.io wrote:

I like the name ruby-unit, in this case we should also consider
changing the namespaces to match (ie: RubyUnit)

Might as well use Minitest:: at that point, right?

Nevermind, there's a lot of old assertions which Minitest drops.
Maybe we can do it long term.

#6 Updated by Robin Dupret about 1 year ago

Hello,

I take the liberty to link to a branch with a beginning of patch that updates the bundled version of Minitest to 5 (https://github.com/robin850/ruby/compare/minitest-five) since this is more or less related to the problem here. IMO, this is really bad to have a "deprecated"/out dated version of a library that you're shipping with by default. I'm conscious that the amount of work would be pretty important to rename all Test::Unit::TestCase classes to Minitest::Test but the wrapper is not so nice.

Moreover, I don't think the amount of work needed to rename the test suite is really worth regarding the final result. The test cases would have to be renamed anyway if we follow Zachary's suggestion (which is legit, I think ; it would make no sense to have a ruby/unit.rb file with a Test::Unit class in it).

I find it sometimes annoying to have to create a Gemfile adding gem 'minitest' in it just to use an up to date version of Minitest.

I'm pretty sure you have good reasons to stuck with Test::Unit inside your test suite, but just my two cents here.

Have a nice day.

#7 Updated by _ wanabe about 1 year ago

  • Related to Feature #9711: Remove test-unit and minitest from stdlib. added

#8 Updated by Hiroshi SHIBATA 9 months ago

  • Status changed from Open to Closed
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: DONTNEED, 2.1: DONTNEED

fixed at r45970

Also available in: Atom PDF