Module: FastlyNsq::ProducerTesting

Included in:
Producer
Defined in:
lib/fastly_nsq/testing.rb

Instance Method Summary collapse

Instance Method Details

#connectObject



180
181
182
183
# File 'lib/fastly_nsq/testing.rb', line 180

def connect
  return super unless FastlyNsq::Testing.enabled?
  @connected = true
end

#connected?Boolean

Returns:

  • (Boolean)


145
146
147
148
149
# File 'lib/fastly_nsq/testing.rb', line 145

def connected?
  return super unless FastlyNsq::Testing.enabled?
  @connected = true if @connected.nil?
  @connected
end

#connectionObject



174
175
176
177
178
# File 'lib/fastly_nsq/testing.rb', line 174

def connection
  return super unless FastlyNsq::Testing.enabled?
  return nil unless connected?
  self
end

#messagesObject

Raises:

  • (NoMethodError)


185
186
187
188
189
# File 'lib/fastly_nsq/testing.rb', line 185

def messages
  raise NoMethodError unless FastlyNsq::Testing.enabled?

  FastlyNsq::Messages.messages[topic]
end

#terminateObject



151
152
153
154
155
# File 'lib/fastly_nsq/testing.rb', line 151

def terminate
  return super unless FastlyNsq::Testing.enabled?

  @connected = false
end

#write(message) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/fastly_nsq/testing.rb', line 157

def write(message)
  return super unless FastlyNsq::Testing.enabled?

  raise FastlyNsq::NotConnectedError unless connected?

  test_message = TestMessage.new(message)
  FastlyNsq::Messages.messages[topic] << test_message

  if FastlyNsq::Testing.inline?
    listener = FastlyNsq.manager.topic_listeners[topic]
    return unless listener
    listener.call test_message
  end

  true
end