1

minitest で rspec before(:all) と同等のことを行うにはどうすればよいでしょうか。実行に永遠にかかるテストのグループがありますが、各テストの前にデータベースをセットアップする必要がなければ、非常に高速になります。

私がやりたいことは次のとおりです。

before(:all) do
  config.transactional_fixtures = false
  DatabaseCleaner.start
end

......
# block of 6 tests in their own describe block.
......

after(:all) do
  config.transactional_fixtures = true
  DatabaseCleaner.clean
end
4

1 に答える 1

2

Minitest は単純に Ruby です。

私はおそらくBEFORE { }ブロックを使用するだけです。テストを実行する前に、セットアップが必要なものをセットアップします。

END { }そのプロセスの残りの半分になります。

Ruby 1.9 Keyword Documentationの時点で、次のように述べられています。

# BEGIN
# Designates, via code block, code to be executed unconditionally before sequential execution of the program begins. Sometimes used to simulate forward references to methods.

   puts times_3(gets.to_i)

   BEGIN {
     def times_3(n)
       n * 3
     end
   }

# END
# Designates, via code block, code to be executed just prior to program termination.

   END { puts "Bye!" }
于 2014-10-22T02:04:55.733 に答える