سؤال

How on earth do I use the after_run class function to run some code after all my tests are done? All my attempts raise NoMethodError:

class MyTest < Minitest::Test
  after_run {
    puts "After run!"
  }
end

# -------------------------------------------------------------------------------

class MyTest < Minitest::Test
  self.after_run {
    puts "After run!"
  }
end

# -------------------------------------------------------------------------------

class MyTest < Minitest::Test
end

MyTest.after_run {
  puts "After run!"
}

Using Minitest 5.2.2

هل كانت مفيدة؟

المحلول

I assumed after_run would run after all the tests in the class, but as Sergio Tulentsev pointed out, it runs after the whole test suite is complete. For the sake of completeness, this is how it's used:

Minitest.after_run {
  puts "The whole test suite is complete"
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top