Class: Oaken::TestSetup
- Inherits:
-
Module
- Object
- Module
- Oaken::TestSetup
- Defined in:
- lib/oaken/test_setup.rb
Instance Method Summary collapse
- #included(klass) ⇒ Object
-
#initialize(loader) ⇒ TestSetup
constructor
A new instance of TestSetup.
Constructor Details
#initialize(loader) ⇒ TestSetup
Returns a new instance of TestSetup.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/oaken/test_setup.rb', line 2 def initialize(loader) @loader = loader # We must inject late enough to call `should_parallelize?`, but before fixtures' `before_setup`. # # So we prepend into `before_setup` and later `super` to have fixtures wrap tests in transactions. instance = self define_method :before_setup do # `should_parallelize?` is only defined when Rails' test `parallelize` macro has been called. loader.replant_seed unless Minitest.parallel_executor.then { _1.respond_to?(:should_parallelize?, true) && _1.send(:should_parallelize?) } instance.remove_method :before_setup # Only run once, so remove before passing to fixtures in `super`. super() end end |
Instance Method Details
#included(klass) ⇒ Object
18 19 20 21 22 |
# File 'lib/oaken/test_setup.rb', line 18 def included(klass) klass.fixtures # Rely on fixtures to setup a shared connection pool and wrap tests in transactions. klass.include @loader.context klass.parallelize_setup { @loader.load_seed } # No need to truncate as parallel test databases are always empty. end |