2

How do I run a suite-level set up and teardown (before and after ALL the tests have run) with minitest 5? I am trying to replicate the functionality of custom test runner that was written for rails 3, currently upgrading it to rails 4.

This may appear to be a copy of Ruby Minitest: Suite- or Class- level setup? but the functionality of .runner has been deprecated in minitest 5.0+

For example I would like these to run before and after all the tests.

def before_suites
  # code to run before the first test
  p "Before everything"
end

def after_suites
  # code to run after the last test
  p "After everything"
end
Community
  • 1
  • 1
john mitsch
  • 171
  • 1
  • 7

1 Answers1

0

I've been looking for similar solution. And here is a proposed solution from minitest README file:

describe Blah do
  SETUP = begin
     # ... this runs once when describe Blah starts
  end
  # ...
end

I've tried this, but since i was using some of test_helper support methods, it didn't quite work out for me. I wrote this simple work-around:

class SearchServiceTest < ActiveSupport::TestCase
  @@init = 0

  def setup
    if @@init.eql?(0)
      .. setup code goes here ..  

      @@init = 1
    end
  end

  ...
end

Not most elegant solution, but worked for me.

skatkov
  • 133
  • 2
  • 10