How to run existing test code in Ruby 2.2

The following code (which does not have a gemfile) works on Ruby 2.1.1, but not Ruby 2.2.0

require "bundler/setup"
gem "minitest", "4.7.5"
require "test/unit"

class TestFoo < Test::Unit::TestCase
  def test_foo
    assert true, "Useless mesage"
    skip "Skip works"
  end
end

On Ruby 2.1.1 I get

Run options: 

# Running tests:

[1/1] TestFoo#test_foo = 0.00 s
  1) Skipped:
TestFoo#test_foo [test_220.rb:8]:
Skip works

Finished tests in 0.004435s, 225.4791 tests/s, 225.4791 assertions/s.
1 tests, 1 assertions, 0 failures, 0 errors, 1 skips

ruby -v: ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin10.0]

But on Ruby 2.2.0 I get

192-168-1-5:test_220 agrimm$ ruby test_220.rb 
Loaded suite test_220
Started
E
===============================================================================
Error: test_foo(TestFoo)
: NoMethodError: undefined method `skip' for #<TestFoo:0x007fb75484f158>
test_220.rb:8:in `test_foo'
      5: class TestFoo < Test::Unit::TestCase
      6:   def test_foo
      7:     assert true, "Useless mesage"
  =>  8:     skip "Skip works"
      9:   end
     10: end
===============================================================================


Finished in 0.001504 seconds.

1 tests, 1 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
0% passed

664.89 tests/s, 664.89 assertions/s
$ ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13]

I suspect this is due to changes related to Ruby 2.2.0 :

Test module update 3.0.8 (removed from the repository, but included in the tarball)

Update minitest 5.4.3 (removed from the repository, but bundled with tarball)

How to make the code work with Ruby 2.2, preferably with the least amount of code changes?

+4
source share
2 answers

Ruby 2.2, test/unit minitest. , Test::Unit::TestCase, . , skip , minitest.

Ruby 2.2 test-unit 3.0.8 minitest 5.4.3, , . , - .

2 :

1. test-unit - rubydoc

Test::Unit::TestCase, test-unit.

, skip omit:

require "test/unit"

class TestFoo < Test::Unit::TestCase
  def test_foo
    assert true, "Useless mesage"
    omit "Omit works"
  end
end

2. minitest - rubydoc

, , require "minitest/autorun" Minitest::Test:

require "minitest/autorun"

class TestFoo < Minitest::Test
  def test_foo
    assert true, "Useless mesage"
    skip "Skip works"
  end
end
+13

backports : test-unit-minitest

+2

All Articles