At_exit and Test::Unit::TestCase

Hi,
I'm migrating the ruby framework that I have from Ruby 1.8.7 to 2.0
In my framework I have some code inside the block at_exit so it will run
after all Ruby code has run... and in 1.8.7 works perfectly when running
any kind of code or even testcases Test::Unit::TestCase, the code was
something like:

require 'my_framework' #at_exit is in my framework

MyTestCase < Test::Unit::TestCase
  def test01
    puts "my first test"
  end
  def test02
    puts "my second test"
  end
end

So when it was run the result was:

my first test
my second test
I'm in the at_exit block

But now in Ruby 2 the at_exit block is run before the testcases:
I'm in the at_exit block
my first test
my second test

Any idea how can i have the at_exit like it was before?

Thanks in advance.

···

--
Posted via http://www.ruby-forum.com/.

The order in which at_exit stuff is run has changed between 1.8 and 1.9. Since test/unit runs via at_exit, you need yours to run _after_ your tests' at_exit and that has now changed.

You can get around this either by doubling up the at_exit, or using minitest's `after_run` call. test/unit in stdlib on 1.9/2.0 is built on top of minitest, so this _should_ be OK, but then again, it is a huge monkeypatch so it may not work right. I haven't tested it against test/unit. That said, it is trivial to convert from test/unit to minitest and you get the benefit of the huge ecosystem that comes along with it.

···

On Dec 12, 2013, at 8:25, Mario Ruiz <lists@ruby-forum.com> wrote:

Hi,
I'm migrating the ruby framework that I have from Ruby 1.8.7 to 2.0
In my framework I have some code inside the block at_exit so it will run
after all Ruby code has run... and in 1.8.7 works perfectly when running
any kind of code or even testcases Test::Unit::TestCase, the code was
something like:

require 'my_framework' #at_exit is in my framework

MyTestCase < Test::Unit::TestCase
def test01
   puts "my first test"
end
def test02
   puts "my second test"
end
end

So when it was run the result was:

my first test
my second test
I'm in the at_exit block

But now in Ruby 2 the at_exit block is run before the testcases:
I'm in the at_exit block
my first test
my second test

Any idea how can i have the at_exit like it was before?