6

I'm using the latest version of Ruby(2.0.0) and Minitest (5.0.8).

I am looking for a way to create 2 methods, a before and an after. The before method should run before Minitest even starts on the testcases and the after should run once ALL of the test have finished.

I already use the setup() and teardown() methods that run before and after each individual test but I'm looking for something that wraps around the whole Minitest suite.

I have seen:

Ruby Minitest: Suite- or Class- level setup?

and

Before/After Suite when using Ruby MiniTest

Which are both out of date with the latest version of Minitest.

Is this still possible?

2 Answers 2

5

The before method is easy, you just configure your test setup to call a method before the Minitest starts.

The after method can be achieve by using the method Minitest.after_run(&block) provided by the Minitest API. Ex:

Minitest.after_run do
  puts 'All tests finished'
  my_method_call()
end
1
  • Thanks a lot, can't believe I couldn't find that
    – CustomNet
    Nov 7, 2013 at 13:41
0

You may want to have a look at minitest-hooks. minitest-hooks extends minitest with before(:all) and after(:all), which do what you want when the structure of your describe block is flat. When you have nested describe blocks, you may want to take an approach that is similar to Thiago's answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.