1

How would I do the equivalent of rspec before(:all) in minitest. I have a group of tests that take forever to run but it would be really fast if I didn't have to setup the database before each test.

What I would like to do is:

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

1 Answer 1

2

Minitest is simply Ruby.

I would probably just use a BEFORE { } block. Get those things setup that you need to get set up before you run your tests.

END { } is going to be the other half of that process.

As of Ruby 1.9 Keyword Documentation states:

# 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
   }

and

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

   END { puts "Bye!" }
Sign up to request clarification or add additional context in comments.

3 Comments

Wouldn't that run at load time instead of runtime?
Yes, each time that program is ran, and exits, it runs through that cycle, hence running before all. It will run when this is loaded, as it is top level, it is 'running code', as opposed to sitting in a method waiting to be evoked. However, that means that it will run at 'runtime', it is top level code for this file.
Thanks so much for taking the time to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.