module Cloudtasker::Testing

Enable/Disable test mode for Cloudtasker

Public Instance Methods

enable!(&block) click to toggle source

Set cloudtasker to real mode temporarily

@param [Proc] &block The block to run in real mode

# File lib/cloudtasker/testing.rb, line 37
def enable!(&block)
  switch_test_mode(:enabled, &block)
end
enabled?() click to toggle source

Return true if Cloudtasker is enabled.

# File lib/cloudtasker/testing.rb, line 62
def enabled?
  !@test_mode || @test_mode == :enabled
end
fake!(&block) click to toggle source

Set cloudtasker to fake mode temporarily

@param [Proc] &block The block to run in fake mode

# File lib/cloudtasker/testing.rb, line 46
def fake!(&block)
  switch_test_mode(:fake, &block)
end
fake?() click to toggle source

Return true if Cloudtasker is in fake mode.

@return [Boolean] True if jobs must be processed through drain calls.

# File lib/cloudtasker/testing.rb, line 71
def fake?
  @test_mode == :fake
end
in_memory?() click to toggle source

Return true if tasks should be managed in memory.

@return [Boolean] True if jobs are managed in memory.

# File lib/cloudtasker/testing.rb, line 89
def in_memory?
  !enabled?
end
inline!(&block) click to toggle source

Set cloudtasker to inline mode temporarily

@param [Proc] &block The block to run in inline mode

# File lib/cloudtasker/testing.rb, line 55
def inline!(&block)
  switch_test_mode(:inline, &block)
end
inline?() click to toggle source

Return true if Cloudtasker is in inline mode.

@return [Boolean] True if jobs are run inline.

# File lib/cloudtasker/testing.rb, line 80
def inline?
  @test_mode == :inline
end
switch_test_mode(mode) { || ... } click to toggle source

Set the test mode, either permanently or temporarily (via block).

@param [Symbol] mode The test mode.

@return [Symbol] The test mode.

# File lib/cloudtasker/testing.rb, line 18
def switch_test_mode(mode)
  if block_given?
    current_mode = @test_mode
    begin
      @test_mode = mode
      yield
    ensure
      @test_mode = current_mode
    end
  else
    @test_mode = mode
  end
end