3

Since it now seems to have replaced TestUnit in 1.9.1, I can't seem to find an equivalent to this. There are times when you really just want a method to run once for the suite of tests. For now I've resorted to some lovely hackery along the lines of:

Class ParseStandardWindTest < MiniTest::Unit::TestCase
  @@reader ||= PolicyDataReader.new(Time.now)  
  @@data ||= @@reader.parse  
  def test_stuff  
    transaction = @@data[:transaction]  
    assert true, transaction  
  end  
end
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
bergyman
  • 4,480
  • 3
  • 23
  • 32
  • See also http://stackoverflow.com/questions/6756488/ruby-minitest-suite-or-class-level-setup and http://stackoverflow.com/questions/5881474/before-after-suite-when-using-ruby-minitest – slothbear Dec 02 '11 at 05:01

2 Answers2

3

Nops, there's only setup and teardown and both are run before/after every test. But your solution seems to do the trick.

Maurício Linhares
  • 39,901
  • 14
  • 121
  • 158
0

It's best to use 'let' I've found.

eg (using minitest/spec)

describe "my amazing test" do

  let(:reader) { PolicyDataReader.new(Time.now) }
  let(:data) {reader.parse}

  it "should parse" do
    transaction = data[:transaction]
    transaction.must_equal true
  end

end

to use minitest/spec simply add

gem 'minitest', require: ['minitest/autorun', 'minitest/spec']

to the test group of your Gemfile

Dave Sag
  • 13,266
  • 14
  • 86
  • 134