class FastlyNsq::Testing

FastlyNsq::Testing.disable! # do it live FastlyNsq::Testing.enable! # re-enable testing mode

Attributes

__test_mode[RW]

Public Class Methods

__set_test_mode(mode) { || ... } click to toggle source
# File lib/fastly_nsq/testing.rb, line 41
def __set_test_mode(mode)
  if block_given?
    current_mode = __test_mode
    begin
      self.__test_mode = mode
      yield
    ensure
      self.__test_mode = current_mode
    end
  else
    self.__test_mode = mode
  end
end
disable!(&block) click to toggle source
# File lib/fastly_nsq/testing.rb, line 55
def disable!(&block)
  __set_test_mode(:disable, &block)
end
disabled?() click to toggle source
# File lib/fastly_nsq/testing.rb, line 71
def disabled?
  __test_mode == :disable
end
enabled?() click to toggle source
# File lib/fastly_nsq/testing.rb, line 67
def enabled?
  __test_mode != :disable
end
fake!(&block) click to toggle source
# File lib/fastly_nsq/testing.rb, line 59
def fake!(&block)
  __set_test_mode(:fake, &block)
end
fake?() click to toggle source
# File lib/fastly_nsq/testing.rb, line 75
def fake?
  __test_mode == :fake
end
inline!(&block) click to toggle source
# File lib/fastly_nsq/testing.rb, line 63
def inline!(&block)
  __set_test_mode(:inline, &block)
end
inline?() click to toggle source
# File lib/fastly_nsq/testing.rb, line 79
def inline?
  __test_mode == :inline
end
message(data:, meta: nil) click to toggle source

Creates a FastlyNsq::TestMessage that is used to create a FastlyNsq::Message where the underlying nsq_message is the TestMessage and not an Nsq::Message. This aids in testing application code that is doing message processing

@param data [String] NSQ message data @param meta [String] NSQ message metadata

@example

test_message = FastlyNsq::Testing.message(data: post_data, meta: {})
processor_klass.call(test_message)
expect(Post.find(post_data['id']).not_to be nil
# File lib/fastly_nsq/testing.rb, line 100
def message(data:, meta: nil)
  test_message = FastlyNsq::TestMessage.new(JSON.dump('data' => data, 'meta' => meta))
  FastlyNsq::Message.new(test_message)
end
reset!() click to toggle source
# File lib/fastly_nsq/testing.rb, line 83
def reset!
  return unless enabled?
  FastlyNsq::Messages.messages.clear
end