Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Before/After methods for Ruby Minitest framework

Tags:

ruby

minitest

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?

like image 923
CustomNet Avatar asked Nov 07 '13 10:11

CustomNet


1 Answers

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
like image 145
Thiago Lewin Avatar answered Sep 28 '22 19:09

Thiago Lewin