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 开始,关键字文档指出:

# 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 回答