fake_smith 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fake_smith/version.rb +1 -1
- data/lib/fake_smith.rb +19 -0
- data/spec/fake_smith_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2de2b0adf126522d621754afe65470839e4f114b
|
4
|
+
data.tar.gz: 3e5d68a2fb74f4065ad5fd098e40f6fd556b1e5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad868e516f31e7574b4e73d595314cf36759a2a9070302f5775041ef2f2ca38de7f9f9d9d3fb95c3cbb82c0d8767d36af80f2f216e2098ae93c87e2b42d07273
|
7
|
+
data.tar.gz: e7239578521cb08218545c23d1b21dafd2cdb09bcbf9d0f2d7a0e79fb3f28754575eae3454aca30c4e6743408374a8efef857f52dcc7f9742a13bd20cd2e0d8e
|
data/lib/fake_smith/version.rb
CHANGED
data/lib/fake_smith.rb
CHANGED
@@ -22,6 +22,15 @@ class FakeSmith
|
|
22
22
|
|
23
23
|
class MessageAckedTwiceError < StandardError; end
|
24
24
|
|
25
|
+
def self.set_reply_handler(queue_name, &blk)
|
26
|
+
@reply_handlers ||= {}
|
27
|
+
@reply_handlers[queue_name] = blk
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.reply_handlers
|
31
|
+
@reply_handlers
|
32
|
+
end
|
33
|
+
|
25
34
|
def self.send_message(queue_name, payload, receiver)
|
26
35
|
raise "no subscribers on queue: #{queue_name}" unless subscriptions[queue_name]
|
27
36
|
receiver = ReceiverDecorator.new(receiver)
|
@@ -150,9 +159,19 @@ module Smith
|
|
150
159
|
blk.call(self) if block_given?
|
151
160
|
end
|
152
161
|
|
162
|
+
def on_reply(_opts, &blk)
|
163
|
+
@on_reply = blk
|
164
|
+
end
|
165
|
+
|
166
|
+
def on_timeout(&blk)
|
167
|
+
end
|
168
|
+
|
153
169
|
def publish(message, &blk)
|
154
170
|
FakeSmith.add_message(@queue_name, message)
|
155
171
|
blk.call if block_given?
|
172
|
+
if FakeSmith.reply_handlers[@queue_name] && @on_reply
|
173
|
+
@on_reply.call(FakeSmith.reply_handlers[@queue_name].call(message))
|
174
|
+
end
|
156
175
|
end
|
157
176
|
|
158
177
|
def message_count(&blk)
|
data/spec/fake_smith_spec.rb
CHANGED
@@ -5,6 +5,7 @@ class MyAgent < Smith::Agent
|
|
5
5
|
receiver("ack_twice_queue", :auto_ack => false).subscribe(&method(:ack_twice))
|
6
6
|
receiver("ack_once_queue", :auto_ack => false).subscribe(&method(:ack_once))
|
7
7
|
receiver("auto_ack_and_ack_queue", :auto_ack => true).subscribe(&method(:auto_ack_and_ack))
|
8
|
+
receiver("send_and_expect_reply", :auto_ack => true).subscribe(&method(:send_and_expect_reply))
|
8
9
|
end
|
9
10
|
|
10
11
|
def ack_twice(payload, receiver)
|
@@ -19,6 +20,18 @@ class MyAgent < Smith::Agent
|
|
19
20
|
def auto_ack_and_ack(payload, receiver)
|
20
21
|
receiver.ack
|
21
22
|
end
|
23
|
+
|
24
|
+
def send_and_expect_reply(payload, receiver)
|
25
|
+
sender("replying_queue") do |q|
|
26
|
+
q.on_reply(:reply_queue_name => "somereplyqueuename") { |response| @replying_worked = true if response == {:correct => "response"} }
|
27
|
+
q.on_timeout { raise "replying epic fail" }
|
28
|
+
q.publish({:correct => "message"})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def replying_worked?
|
33
|
+
@replying_worked
|
34
|
+
end
|
22
35
|
end
|
23
36
|
|
24
37
|
describe FakeSmith do
|
@@ -45,4 +58,13 @@ describe FakeSmith do
|
|
45
58
|
FakeSmith.send_message("ack_once_queue", message, receiver)
|
46
59
|
end
|
47
60
|
end
|
61
|
+
|
62
|
+
describe 'replying' do
|
63
|
+
it 'allows setting reply handlers' do
|
64
|
+
FakeSmith.set_reply_handler("replying_queue") do |send_message|
|
65
|
+
{:correct => "response"} if send_message == {:correct => "message"}
|
66
|
+
end
|
67
|
+
FakeSmith.send_message("send_and_expect_reply", message, receiver)
|
68
|
+
end
|
69
|
+
end
|
48
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_smith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dylan Griffith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|