Sha256: 948e01d8d0ab989596146cd8935866a2cc4bbde59afed05c61b2c41d329427d3

Contents?: true

Size: 1.22 KB

Versions: 11

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module GlobalRegistry #:nodoc:
  module Bindings #:nodoc:
    class Testing
      class << self
        attr_accessor :__test_mode

        def __set_test_mode(mode)
          if block_given?
            current_mode = __test_mode
            begin
              self.__test_mode = mode
              yield
            ensure
              self.__test_mode = current_mode
            end
          else
            self.__test_mode = mode
          end
        end

        def skip_workers!(&block)
          __set_test_mode(:skip, &block)
        end

        def disable_test_helper!(&block)
          __set_test_mode(:disable, &block)
        end

        def enabled?
          __test_mode != :disable
        end

        def disabled?
          __test_mode == :disable
        end

        def skip?
          __test_mode == :skip
        end
      end
    end

    class Worker
      class << self
        alias perform_async_real perform_async

        def perform_async(*args)
          return if GlobalRegistry::Bindings::Testing.skip?
          perform_async_real(*args)
        end
      end
    end
  end
end

# Default to disabling testing helpers
GlobalRegistry::Bindings::Testing.disable_test_helper!

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
global-registry-bindings-0.6.2 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.6.1 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.6.0 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.5.0 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.4.0 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.3.3 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.3.2 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.3.1 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.3.0 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.2.0 lib/global_registry_bindings/testing.rb
global-registry-bindings-0.1.9 lib/global_registry_bindings/testing.rb