Class: Polyn::Testing::MockNats
- Inherits:
-
Object
- Object
- Polyn::Testing::MockNats
- Defined in:
- lib/polyn/testing/mock_nats.rb
Overview
Mock Nats connection for applications to use in testing
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#nats ⇒ Object
readonly
Returns the value of attribute nats.
Instance Method Summary collapse
- #add_consumer(consumer) ⇒ Object
-
#initialize(nats) ⇒ MockNats
constructor
A new instance of MockNats.
- #jetstream ⇒ Object
- #publish(subject, data, reply_to = nil, **opts) ⇒ Object
- #subscribe(subject, _opts = {}, &callback) ⇒ Object
Constructor Details
#initialize(nats) ⇒ MockNats
Returns a new instance of MockNats.
14 15 16 17 18 19 |
# File 'lib/polyn/testing/mock_nats.rb', line 14 def initialize(nats) @nats = nats @messages = [] @subscribers = [] @consumers = [] end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
21 22 23 |
# File 'lib/polyn/testing/mock_nats.rb', line 21 def @messages end |
#nats ⇒ Object (readonly)
Returns the value of attribute nats.
21 22 23 |
# File 'lib/polyn/testing/mock_nats.rb', line 21 def nats @nats end |
Instance Method Details
#add_consumer(consumer) ⇒ Object
39 40 41 |
# File 'lib/polyn/testing/mock_nats.rb', line 39 def add_consumer(consumer) @consumers << consumer end |
#jetstream ⇒ Object
35 36 37 |
# File 'lib/polyn/testing/mock_nats.rb', line 35 def jetstream @jetstream ||= MockJetStream.new(self) end |
#publish(subject, data, reply_to = nil, **opts) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/polyn/testing/mock_nats.rb', line 23 def publish(subject, data, reply_to = nil, **opts) msg = Polyn::Testing::MockMsg.new(subject: subject, data: data, reply: reply_to, header: opts[:header]) send_to_subscribers(msg) @messages << msg update_consumers end |
#subscribe(subject, _opts = {}, &callback) ⇒ Object
31 32 33 |
# File 'lib/polyn/testing/mock_nats.rb', line 31 def subscribe(subject, _opts = {}, &callback) @subscribers << { subject: subject, callback: callback } end |