Is there an RSpec equivalent before (: all) in MiniTest?

Since now it looks like it has replaced TestUnit in 1.9.1, I cannot find the equivalent of this. There are times when you really want the method to run once for a set of tests. At the moment, I have resorted to excellent hacking in the following areas:

Class ParseStandardWindTest < MiniTest::Unit::TestCase
  @@reader ||= PolicyDataReader.new(Time.now)  
  @@data ||= @@reader.parse  
  def test_stuff  
    transaction = @@data[:transaction]  
    assert true, transaction  
  end  
end
+3
source share
2 answers

Nops, there is setup and separation , and both are performed before / after each test. But your decision seems to do the trick.

+3
source

It is best to use the "let" I found.

e.g. (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

minitest/spec

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

Gemfile

0

Source: https://habr.com/ru/post/1739388/


All Articles