Module: FastlyNsq::ConsumerTesting

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

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(klass) ⇒ Object



270
271
272
273
# File 'lib/fastly_nsq/testing.rb', line 270

def self.prepended(klass)
  klass.prepend(ClassMethods)
  super
end

Instance Method Details

#connect(*args) ⇒ Object



286
287
288
289
# File 'lib/fastly_nsq/testing.rb', line 286

def connect(*args)
  return super(*args) unless FastlyNsq::Testing.enabled?
  @connected = FakeConnection.new
end

#connected?Boolean



279
280
281
282
283
284
# File 'lib/fastly_nsq/testing.rb', line 279

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

  @connected
end

#empty?Boolean



291
292
293
# File 'lib/fastly_nsq/testing.rb', line 291

def empty?
  FastlyNsq::Testing.enabled? ? messages.empty? : super
end

#messagesObject

Raises:

  • (NoMethodError)


311
312
313
314
315
# File 'lib/fastly_nsq/testing.rb', line 311

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

  FastlyNsq::Messages.messages[topic]
end

#popObject



295
296
297
# File 'lib/fastly_nsq/testing.rb', line 295

def pop
  FastlyNsq::Testing.enabled? ? messages(topic)&.pop : super
end

#pop_without_blockingObject



299
300
301
# File 'lib/fastly_nsq/testing.rb', line 299

def pop_without_blocking
  FastlyNsq::Testing.enabled? ? messages(topic)&.pop : super
end

#sizeObject



303
304
305
# File 'lib/fastly_nsq/testing.rb', line 303

def size
  FastlyNsq::Testing.enabled? ? messages.size : super
end

#terminateObject



275
276
277
# File 'lib/fastly_nsq/testing.rb', line 275

def terminate
  FastlyNsq::Testing.enabled? || super
end

#terminated?Boolean



307
308
309
# File 'lib/fastly_nsq/testing.rb', line 307

def terminated?
  FastlyNsq::Testing.enabled? ? false : super
end