Sha256: 76d990ad55bc1b487571f67b3afc32aa59b9505ddce23ecc7a3383a5eb15848b

Contents?: true

Size: 937 Bytes

Versions: 8

Compression:

Stored size: 937 Bytes

Contents

module Reactor
  TEST_MODE_SUBSCRIBERS = Set.new
  @@test_mode = false

  module_function

  def test_mode?
    @@test_mode
  end

  def test_mode!
    @@test_mode = true
  end

  def disable_test_mode!
    @@test_mode = false
  end

  def in_test_mode
    test_mode!
    (yield if block_given?).tap { disable_test_mode! }
  end

  def test_mode_subscribers
    TEST_MODE_SUBSCRIBERS
  end

  def enable_test_mode_subscriber(klass)
    test_mode_subscribers << klass
  end

  def disable_test_mode_subscriber(klass)
    test_mode_subscribers.delete klass
  end

  def with_subscriber_enabled(klass)
    enable_test_mode_subscriber klass
    yield if block_given?
  ensure
    disable_test_mode_subscriber klass
  end

  def clear_test_subscribers!
    test_mode_subscribers.each {|klass| test_mode_subscribers.delete klass }
  end

  def test_mode_subscriber_enabled?(subscriber)
    test_mode_subscribers.include?(subscriber)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reactor-0.19.0 lib/reactor/testing.rb
reactor-0.18.0 lib/reactor/testing.rb
reactor-0.17.0 lib/reactor/testing.rb
reactor-0.16.1 lib/reactor/testing.rb
reactor-0.16.0 lib/reactor/testing.rb
reactor-0.15.1 lib/reactor/testing.rb
reactor-0.15.0 lib/reactor/testing.rb
reactor-0.14.0 lib/reactor/testing.rb