module Cloudenvoy::Testing
Enable/Disable test mode for Cloudenvoy
Public Instance Methods
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 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
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
Return true if Cloudenvoy
is enabled.
# File lib/cloudenvoy/testing.rb, line 53 def enabled? !@test_mode || @test_mode == :enabled end
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
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
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
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
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