module Cloudenvoy::Testing

Enable/Disable test mode for Cloudenvoy

Public Instance Methods

clear(topic) click to toggle source

Clear all messages in a specific topic.

@param [String] name The topic to clear.

@return [Array] The cleared array.

# File lib/cloudenvoy/testing.rb, line 91
def clear(topic)
  Cloudenvoy::Backend::MemoryPubSub.clear(topic)
end
clear_all() click to toggle source

Clear all messages across all topics.

@param [String] name The topic to clear.

# File lib/cloudenvoy/testing.rb, line 80
def clear_all
  Cloudenvoy::Backend::MemoryPubSub.clear_all
end
enable!(&block) click to toggle source

Set cloudenvoy to real mode temporarily

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

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

Return true if Cloudenvoy is enabled.

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

Set cloudenvoy to fake mode temporarily

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

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

Return true if Cloudenvoy is in fake mode.

@return [Boolean] True if messages should be stored in memory.

# File lib/cloudenvoy/testing.rb, line 62
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/cloudenvoy/testing.rb, line 71
def in_memory?
  !enabled?
end
queue(topic) click to toggle source

Return the message queue for a specific topic.

@param [String] name The topic to retrieve.

@return [Array] The list of messages for the provided topic

# File lib/cloudenvoy/testing.rb, line 102
def queue(topic)
  Cloudenvoy::Backend::MemoryPubSub.queue(topic)
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/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