0

I want to change my following code

load "API.rb"
require 'minitest/spec'
require 'minitest/autorun'

class Test < MiniTest::Unit::TestCase
  MiniTest::Assertions.diff = nil
  def setup
  end

  def test_character_detection
    assert_equal "Gandalf", Story.get_first_character(2717)
  end
end

puts "TEST"

so tests will run before normal code (in this case - 'puts "TEST"').

Bulwersator
  • 1,102
  • 2
  • 12
  • 30

1 Answers1

1

Sorry for late answer. Minitests are artful.

minitest/autorun uses at_exit method. It executes the given block when interpreter's work almost done. Roughly speaking "at the end" of your program's lifetime. Though you can call at_exit method more than once and blocks will execute in LIFO order.


More interesting details about at_exit and its usage you can find here.

Also you may look at minitests source code. (in this file at_exit called)

Good luck!

user2422869
  • 750
  • 7
  • 17