Module: Elasticsearch::Extensions::Test::StartupShutdown
- Defined in:
- lib/elasticsearch/extensions/test/startup_shutdown.rb
Overview
Startup/shutdown support for test suites
Example:
class MyTest < Test::Unit::TestCase
extend Elasticsearch::Extensions::Test::StartupShutdown
startup { puts "Suite starting up..." }
shutdown { puts "Suite shutting down..." }
end
*** IMPORTANT NOTE: **********************************************************
You have to register the handler for shutdown before requiring ‘test/unit’:
# File: test_helper.rb
at_exit { MyTest.__run_at_exit_hooks }
require 'test/unit'
The API follows Test::Unit 2.0 <github.com/test-unit/test-unit/blob/master/lib/test/unit/testcase.rb>
Constant Summary collapse
- @@started =
false
Instance Method Summary collapse
- #__run_at_exit_hooks ⇒ Object
- #shutdown(&block) ⇒ Object
- #started? ⇒ Boolean
- #startup {|block| ... } ⇒ Object
Instance Method Details
#__run_at_exit_hooks ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/elasticsearch/extensions/test/startup_shutdown.rb', line 61 def __run_at_exit_hooks return unless started? STDERR.puts ANSI.faint("Running at_exit hooks...") puts ANSI.faint('-'*80) @@shutdown_blocks.each { |b| b.call } puts ANSI.faint('-'*80) end |
#shutdown(&block) ⇒ Object
53 54 55 |
# File 'lib/elasticsearch/extensions/test/startup_shutdown.rb', line 53 def shutdown &block @@shutdown_blocks << block if block_given? end |
#started? ⇒ Boolean
57 58 59 |
# File 'lib/elasticsearch/extensions/test/startup_shutdown.rb', line 57 def started? !! @@started end |
#startup {|block| ... } ⇒ Object
47 48 49 50 51 |
# File 'lib/elasticsearch/extensions/test/startup_shutdown.rb', line 47 def startup &block return if started? @@started = true yield block if block_given? end |