Module: Cloudenvoy::Testing

Defined in:
lib/cloudenvoy/testing.rb

Overview

Enable/Disable test mode for Cloudenvoy

Class Method Summary collapse

Class Method Details

.clear(topic) ⇒ Array

Clear all messages in a specific topic.

Parameters:

  • name (String)

    The topic to clear.

Returns:

  • (Array)

    The cleared array.



91
92
93
# File 'lib/cloudenvoy/testing.rb', line 91

def clear(topic)
  Cloudenvoy::Backend::MemoryPubSub.clear(topic)
end

.clear_allObject

Clear all messages across all topics.

Parameters:

  • name (String)

    The topic to clear.



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

def clear_all
  Cloudenvoy::Backend::MemoryPubSub.clear_all
end

.enable!(&block) ⇒ Object

Set cloudenvoy to real mode temporarily

Parameters:

  • &block (Proc)

    The block to run in real mode



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

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

.enabled?Boolean

Return true if Cloudenvoy is enabled.

Returns:

  • (Boolean)


53
54
55
# File 'lib/cloudenvoy/testing.rb', line 53

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

.fake!(&block) ⇒ Object

Set cloudenvoy to fake mode temporarily

Parameters:

  • &block (Proc)

    The block to run in fake mode



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

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

.fake?Boolean

Return true if Cloudenvoy is in fake mode.

Returns:

  • (Boolean)

    True if messages should be stored in memory.



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

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.



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

def in_memory?
  !enabled?
end

.queue(topic) ⇒ Array

Return the message queue for a specific topic.

Parameters:

  • name (String)

    The topic to retrieve.

Returns:

  • (Array)

    The list of messages for the provided topic



102
103
104
# File 'lib/cloudenvoy/testing.rb', line 102

def queue(topic)
  Cloudenvoy::Backend::MemoryPubSub.queue(topic)
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/cloudenvoy/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