Sha256: c3cdb99932f4fbebfb23c2e1cdd9512d3ec9229b5ae3d5ce0c7ba8aa283e1930

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8

require 'minitest'

module TuneMyGc
  module Spies
    class Minitest
      def initialize
        @tests_processed = 0
        @tests_limit = nil
      end

      def install
        MiniTest::Unit::TestCase.__send__(:include, hooks_module)
        TuneMyGc.log "hooked: minitest"
      end

      def uninstall
        TuneMyGc.uninstall_gc_tracepoint
        TuneMyGc.log "uninstalled GC tracepoint"
        MiniTest::Unit::TestCase.__send__(:include, disabled_hooks_module)
        TuneMyGc.log "uninstalled minitest spy"
      end

      def check_uninstall
        if ENV["RUBY_GC_TUNE_TESTS"]
          @tests_limit ||= Integer(ENV["RUBY_GC_TUNE_TESTS"])
          @tests_processed += 1
          if @tests_processed == @tests_limit
            uninstall
            TuneMyGc.log "kamikaze after #{@tests_processed} of #{@tests_limit} tests"
          end
        end
      end

      def hooks_module
        Module.new do
          def before_setup
            tunemygc_before_setup
            super
          end

          def after_teardown
            super
            tunemygc_after_teardown
          end

          private
          def tunemygc_before_setup
            TuneMyGc.processing_started
          end

          def tunemygc_after_teardown
            TuneMyGc.processing_ended
          end
        end
      end

      def disabled_hooks_module
        Module.new do
          private
          def tunemygc_before_setup
            # noop
          end

          def tunemygc_after_teardown
            # noop
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tunemygc-1.0.22 lib/tunemygc/spies/minitest.rb
tunemygc-1.0.21 lib/tunemygc/spies/minitest.rb
tunemygc-1.0.20 lib/tunemygc/spies/minitest.rb
tunemygc-1.0.18 lib/tunemygc/spies/minitest.rb
tunemygc-1.0.17 lib/tunemygc/spies/minitest.rb