class FastlyNsq::TestMessage

Stub for Nsq::Message used for testing. Use this class instead of a struct or test stubs when testing application logic that requires a Nsq::Message.

Attributes

attempts[R]
id[R]
raw_body[R]

Public Class Methods

new(raw_body) click to toggle source
# File lib/fastly_nsq/testing.rb, line 122
def initialize(raw_body)
  @raw_body = raw_body
  @id       = Digest::SHA1.hexdigest(raw_body.to_s + Time.now.to_s)
  @attempts = 0
end

Public Instance Methods

body() click to toggle source
# File lib/fastly_nsq/testing.rb, line 128
def body
  JSON.parse(JSON.dump(raw_body))
rescue JSON::ParserError
  raw_body
end
finish() click to toggle source
# File lib/fastly_nsq/testing.rb, line 134
def finish
  FastlyNsq::Messages.messages.find { |_, ms| ms.delete(self) }
end
requeue(*) click to toggle source
# File lib/fastly_nsq/testing.rb, line 138
def requeue(*)
  @attempts += 1
  true
end