Sha256: 2519e7096fb12e85623b364a03f1992ae8f88de4dc217e0a0e8cd289b93e4f13

Contents?: true

Size: 1.48 KB

Versions: 27

Compression:

Stored size: 1.48 KB

Contents

module Elasticsearch
  module Extensions
    module Test
      # 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
      # <https://github.com/test-unit/test-unit/blob/master/lib/test/unit/testcase.rb>
      #
      module StartupShutdown
        @@started           = false
        @@shutdown_blocks ||= []

        def startup &block
          return if started?
          @@started = true
          yield block if block_given?
        end

        def shutdown &block
          @@shutdown_blocks << block if block_given?
        end

        def started?
          !! @@started
        end

        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
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
elasticsearch-extensions-0.0.31 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.30 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.29 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.28 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.27 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.26 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.25 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.24 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.23 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.22 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.21 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.20 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.19 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.18 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.17 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.16 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.15 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.14 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.13 lib/elasticsearch/extensions/test/startup_shutdown.rb
elasticsearch-extensions-0.0.12 lib/elasticsearch/extensions/test/startup_shutdown.rb