fake_smith 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fake_smith.gemspec +1 -0
- data/lib/fake_smith/version.rb +1 -1
- data/lib/fake_smith.rb +26 -3
- data/spec/fake_smith_spec.rb +48 -0
- data/spec/spec_helper.rb +5 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e4a94a848958df1c1147d6bcb12271262d8e291
|
4
|
+
data.tar.gz: 1d27e0771e7c00e52ec7ab2c22f7c4df35030519
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 961ce56c9e37ca2c2b31d47369115222ad8b0950cee4de109af8d70c54d427e946a1e04b95f7e5408af2176fbf7fe256069efc6a2d56db6db1c2f0d337eeedf3
|
7
|
+
data.tar.gz: f3c7db3333eacd9687a946b3909a42cff2b956b8f0fbb016cfda997c5becd095bf3da4d33837f00d7c8788eb226b65c160360175bb219beebb80cc92e1bcd437
|
data/fake_smith.gemspec
CHANGED
data/lib/fake_smith/version.rb
CHANGED
data/lib/fake_smith.rb
CHANGED
@@ -1,14 +1,33 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require "smith/agent"
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
2
6
|
require "fake_smith/version"
|
3
7
|
|
4
8
|
class FakeSmith
|
9
|
+
class ReceiverDecorator < SimpleDelegator
|
10
|
+
def ack
|
11
|
+
raise MessageAckedTwiceError, "message was acked twice" if @acked
|
12
|
+
@acked = true
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class MessageAckedTwiceError < StandardError; end
|
18
|
+
|
5
19
|
def self.send_message(queue_name, payload, receiver)
|
6
20
|
raise "no subscribers on queue: #{queue_name}" unless subscriptions[queue_name]
|
21
|
+
receiver = ReceiverDecorator.new(receiver)
|
22
|
+
opts = subscriptions_options[queue_name]
|
23
|
+
auto_ack = opts.key?(:auto_ack) ? opts[:auto_ack] : true
|
24
|
+
receiver.ack if auto_ack
|
7
25
|
subscriptions[queue_name].call(payload, receiver)
|
8
26
|
end
|
9
27
|
|
10
|
-
def self.define_subscription(queue_name, &blk)
|
28
|
+
def self.define_subscription(queue_name, options, &blk)
|
11
29
|
subscriptions[queue_name] = blk
|
30
|
+
subscriptions_options[queue_name] = options
|
12
31
|
end
|
13
32
|
|
14
33
|
def self.get_messages(queue_name)
|
@@ -48,6 +67,10 @@ class FakeSmith
|
|
48
67
|
@subscriptions ||= {}
|
49
68
|
end
|
50
69
|
|
70
|
+
def self.subscriptions_options
|
71
|
+
@subscriptions_options ||= {}
|
72
|
+
end
|
73
|
+
|
51
74
|
def self.clear_subscriptions
|
52
75
|
@subscriptions = {}
|
53
76
|
end
|
@@ -88,7 +111,7 @@ module Smith
|
|
88
111
|
end
|
89
112
|
|
90
113
|
def subscribe(&blk)
|
91
|
-
FakeSmith.define_subscription(@queue_name, &blk)
|
114
|
+
FakeSmith.define_subscription(@queue_name, @options, &blk)
|
92
115
|
end
|
93
116
|
|
94
117
|
def requeue_parameters(opts)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'fake_smith'
|
2
|
+
|
3
|
+
class MyAgent < Smith::Agent
|
4
|
+
def run
|
5
|
+
receiver("ack_twice_queue", :auto_ack => false).subscribe(&method(:ack_twice))
|
6
|
+
receiver("ack_once_queue", :auto_ack => false).subscribe(&method(:ack_once))
|
7
|
+
receiver("auto_ack_and_ack_queue", :auto_ack => true).subscribe(&method(:auto_ack_and_ack))
|
8
|
+
end
|
9
|
+
|
10
|
+
def ack_twice(payload, receiver)
|
11
|
+
receiver.ack
|
12
|
+
receiver.ack
|
13
|
+
end
|
14
|
+
|
15
|
+
def ack_once(payload, receiver)
|
16
|
+
receiver.ack
|
17
|
+
end
|
18
|
+
|
19
|
+
def auto_ack_and_ack(payload, receiver)
|
20
|
+
receiver.ack
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe FakeSmith do
|
25
|
+
let(:receiver) { double(:receiver, :ack => true) }
|
26
|
+
let(:message) { {} }
|
27
|
+
let(:agent) { MyAgent.new }
|
28
|
+
before(:each) do
|
29
|
+
agent.run
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'acking messages twice' do
|
33
|
+
it 'raises errors' do
|
34
|
+
expect { FakeSmith.send_message("ack_twice_queue", message, receiver) }.to raise_error(FakeSmith::MessageAckedTwiceError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'raises errors when acking once and auto_ack' do
|
38
|
+
expect { FakeSmith.send_message("auto_ack_and_ack_queue", message, receiver) }.to raise_error(FakeSmith::MessageAckedTwiceError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'acking' do
|
43
|
+
it 'acks the passed in receiver' do
|
44
|
+
expect(receiver).to receive(:ack)
|
45
|
+
FakeSmith.send_message("ack_once_queue", message, receiver)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
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.3.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-
|
11
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Gem For Stubbing Smith in tests
|
56
70
|
email:
|
57
71
|
- dyl.griffith@gmail.com
|
@@ -67,6 +81,8 @@ files:
|
|
67
81
|
- fake_smith.gemspec
|
68
82
|
- lib/fake_smith.rb
|
69
83
|
- lib/fake_smith/version.rb
|
84
|
+
- spec/fake_smith_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
70
86
|
homepage: https://github.com/DylanGriffith/fake_smith
|
71
87
|
licenses:
|
72
88
|
- GPL-3
|
@@ -91,4 +107,6 @@ rubygems_version: 2.2.2
|
|
91
107
|
signing_key:
|
92
108
|
specification_version: 4
|
93
109
|
summary: Gem For Stubbing Smith in tests
|
94
|
-
test_files:
|
110
|
+
test_files:
|
111
|
+
- spec/fake_smith_spec.rb
|
112
|
+
- spec/spec_helper.rb
|