Module: Cloudtasker::Testing

Defined in:
lib/cloudtasker/testing.rb

Overview

Enable/Disable test mode for Cloudtasker

Class Method Summary collapse

Class Method Details

.enable!(&block) ⇒ Object

Set cloudtasker to real mode temporarily

Parameters:

  • &block (Proc)

    The block to run in real mode



37
38
39
# File 'lib/cloudtasker/testing.rb', line 37

def enable!(&block)
  switch_test_mode(:enabled, &block)
end

.enabled?Boolean

Return true if Cloudtasker is enabled.

Returns:

  • (Boolean)


62
63
64
# File 'lib/cloudtasker/testing.rb', line 62

def enabled?
  !@test_mode || @test_mode == :enabled
end

.fake!(&block) ⇒ Object

Set cloudtasker to fake mode temporarily

Parameters:

  • &block (Proc)

    The block to run in fake mode



46
47
48
# File 'lib/cloudtasker/testing.rb', line 46

def fake!(&block)
  switch_test_mode(:fake, &block)
end

.fake?Boolean

Return true if Cloudtasker is in fake mode.

Returns:

  • (Boolean)

    True if jobs must be processed through drain calls.



71
72
73
# File 'lib/cloudtasker/testing.rb', line 71

def fake?
  @test_mode == :fake
end

.in_memory?Boolean

Return true if tasks should be managed in memory.

Returns:

  • (Boolean)

    True if jobs are managed in memory.



89
90
91
# File 'lib/cloudtasker/testing.rb', line 89

def in_memory?
  !enabled?
end

.inline!(&block) ⇒ Object

Set cloudtasker to inline mode temporarily

Parameters:

  • &block (Proc)

    The block to run in inline mode



55
56
57
# File 'lib/cloudtasker/testing.rb', line 55

def inline!(&block)
  switch_test_mode(:inline, &block)
end

.inline?Boolean

Return true if Cloudtasker is in inline mode.

Returns:

  • (Boolean)

    True if jobs are run inline.



80
81
82
# File 'lib/cloudtasker/testing.rb', line 80

def inline?
  @test_mode == :inline
end

.switch_test_mode(mode) ⇒ Symbol

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

Parameters:

  • mode (Symbol)

    The test mode.

Returns:

  • (Symbol)

    The test mode.



18
19
20
21
22
23
24
25
26
27
28
29
30
# 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