bunny-mock 1.0.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 +7 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/.travis.yml +10 -0
- data/.yardopts +7 -0
- data/Gemfile +15 -0
- data/LICENSE +20 -0
- data/README.md +151 -0
- data/bunny-mock.gemspec +27 -0
- data/lib/bunny-mock.rb +48 -0
- data/lib/bunny_mock/channel.rb +310 -0
- data/lib/bunny_mock/exchange.rb +266 -0
- data/lib/bunny_mock/exchanges/direct.rb +24 -0
- data/lib/bunny_mock/exchanges/fanout.rb +28 -0
- data/lib/bunny_mock/exchanges/headers.rb +33 -0
- data/lib/bunny_mock/exchanges/topic.rb +51 -0
- data/lib/bunny_mock/queue.rb +208 -0
- data/lib/bunny_mock/session.rb +85 -0
- data/lib/bunny_mock/version.rb +7 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/unit/bunny_mock/channel_spec.rb +175 -0
- data/spec/unit/bunny_mock/exchange_spec.rb +145 -0
- data/spec/unit/bunny_mock/exchanges/direct_spec.rb +28 -0
- data/spec/unit/bunny_mock/exchanges/fanout_spec.rb +31 -0
- data/spec/unit/bunny_mock/exchanges/topic_spec.rb +70 -0
- data/spec/unit/bunny_mock/queue_spec.rb +145 -0
- data/spec/unit/bunny_mock/session_spec.rb +79 -0
- data/spec/unit/bunny_mock_spec.rb +28 -0
- metadata +97 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
describe BunnyMock::Exchanges::Fanout do
|
2
|
+
|
3
|
+
context '#deliver' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@source = @channel.fanout 'xchg.source'
|
7
|
+
|
8
|
+
@first = @channel.queue 'queue.first'
|
9
|
+
@second = @channel.queue 'queue.second'
|
10
|
+
@third = @channel.queue 'queue.third'
|
11
|
+
|
12
|
+
@first.bind @source
|
13
|
+
@second.bind @source
|
14
|
+
@third.bind @source
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should only deliver to all routes' do
|
18
|
+
|
19
|
+
@source.publish 'Testing message', routing_key: 'queue.second'
|
20
|
+
|
21
|
+
expect(@first.message_count).to eq(1)
|
22
|
+
expect(@first.pop[:message]).to eq('Testing message')
|
23
|
+
|
24
|
+
expect(@second.message_count).to eq(1)
|
25
|
+
expect(@second.pop[:message]).to eq('Testing message')
|
26
|
+
|
27
|
+
expect(@third.message_count).to eq(1)
|
28
|
+
expect(@third.pop[:message]).to eq('Testing message')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
describe BunnyMock::Exchanges::Topic do
|
2
|
+
|
3
|
+
context '#deliver' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@source = @channel.topic 'xchg.source'
|
7
|
+
|
8
|
+
@first = @channel.queue 'queue.category.sub.first'
|
9
|
+
@second = @channel.queue 'queue.category.second'
|
10
|
+
@third = @channel.queue 'queue.topic.sub.third'
|
11
|
+
|
12
|
+
@first.bind @source
|
13
|
+
@second.bind @source
|
14
|
+
@third.bind @source
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should deliver with no wildcards' do
|
18
|
+
|
19
|
+
@source.publish 'Testing message', routing_key: 'queue.category.second'
|
20
|
+
|
21
|
+
expect(@first.message_count).to eq(0)
|
22
|
+
expect(@third.message_count).to eq(0)
|
23
|
+
|
24
|
+
expect(@second.message_count).to eq(1)
|
25
|
+
expect(@second.pop[:message]).to eq('Testing message')
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'should deliver with wildcards' do
|
29
|
+
|
30
|
+
it 'for single wildcards' do
|
31
|
+
|
32
|
+
@source.publish 'Testing message', routing_key: 'queue.*.sub.*'
|
33
|
+
|
34
|
+
expect(@second.message_count).to eq(0)
|
35
|
+
|
36
|
+
expect(@first.message_count).to eq(1)
|
37
|
+
expect(@first.pop[:message]).to eq('Testing message')
|
38
|
+
|
39
|
+
expect(@third.message_count).to eq(1)
|
40
|
+
expect(@third.pop[:message]).to eq('Testing message')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'for multiple wildcards' do
|
44
|
+
|
45
|
+
@source.publish 'Testing message', routing_key: 'queue.category.#'
|
46
|
+
|
47
|
+
expect(@third.message_count).to eq(0)
|
48
|
+
|
49
|
+
expect(@first.message_count).to eq(1)
|
50
|
+
expect(@first.pop[:message]).to eq('Testing message')
|
51
|
+
|
52
|
+
expect(@second.message_count).to eq(1)
|
53
|
+
expect(@second.pop[:message]).to eq('Testing message')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'for a mixed wildcards' do
|
57
|
+
|
58
|
+
@source.publish 'Testing message', routing_key: '#.sub.*'
|
59
|
+
|
60
|
+
expect(@second.message_count).to eq(0)
|
61
|
+
|
62
|
+
expect(@first.message_count).to eq(1)
|
63
|
+
expect(@first.pop[:message]).to eq('Testing message')
|
64
|
+
|
65
|
+
expect(@third.message_count).to eq(1)
|
66
|
+
expect(@third.pop[:message]).to eq('Testing message')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
describe BunnyMock::Queue do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@queue = @channel.queue 'testing.q'
|
5
|
+
end
|
6
|
+
|
7
|
+
context '#publish' do
|
8
|
+
|
9
|
+
it 'should add message' do
|
10
|
+
|
11
|
+
@queue.publish 'This is a test message'
|
12
|
+
|
13
|
+
expect(@queue.message_count).to eq(1)
|
14
|
+
expect(@queue.pop[:message]).to eq('This is a test message')
|
15
|
+
expect(@queue.message_count).to eq(0)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#bind' do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@source = @channel.exchange 'xchg.source'
|
23
|
+
@receiver = @channel.queue 'queue.receiver'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should bind by exchange instance' do
|
27
|
+
|
28
|
+
@receiver.bind @source
|
29
|
+
|
30
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
31
|
+
expect(@source.has_binding?(@receiver)).to be_truthy
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should bind by exchange name' do
|
35
|
+
|
36
|
+
@receiver.bind @source.name
|
37
|
+
|
38
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
39
|
+
expect(@source.has_binding?(@receiver)).to be_truthy
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#unbind' do
|
44
|
+
|
45
|
+
before do
|
46
|
+
@source = @channel.exchange 'xchg.source'
|
47
|
+
@receiver = @channel.queue 'queue.receiver'
|
48
|
+
|
49
|
+
@receiver.bind @source
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should unbind by exchange instance' do
|
53
|
+
|
54
|
+
@receiver.unbind @source
|
55
|
+
|
56
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
57
|
+
expect(@source.has_binding?(@receiver)).to be_falsey
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should unbind by exchange name' do
|
61
|
+
|
62
|
+
@receiver.unbind @source.name
|
63
|
+
|
64
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
65
|
+
expect(@source.has_binding?(@receiver)).to be_falsey
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context '#bound_to?' do
|
70
|
+
|
71
|
+
before do
|
72
|
+
@source = @channel.exchange 'xchg.source'
|
73
|
+
@receiver = @channel.queue 'queue.receiver'
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'should return true if bound' do
|
77
|
+
|
78
|
+
it 'by instance' do
|
79
|
+
|
80
|
+
@receiver.bind @source
|
81
|
+
|
82
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'by name' do
|
86
|
+
|
87
|
+
@receiver.bind @source
|
88
|
+
|
89
|
+
expect(@receiver.bound_to?(@source.name)).to be_truthy
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'by routing key' do
|
93
|
+
|
94
|
+
@receiver.bind @source, routing_key: 'queue.route'
|
95
|
+
|
96
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
97
|
+
expect(@receiver.bound_to?(@source, routing_key: 'queue.route')).to be_truthy
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'return false otherwise' do
|
102
|
+
|
103
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context '#message_count' do
|
108
|
+
|
109
|
+
it 'should return number of messages in queue' do
|
110
|
+
|
111
|
+
@queue.publish 'First'
|
112
|
+
@queue.publish 'Second'
|
113
|
+
|
114
|
+
expect(@queue.message_count).to eq(2)
|
115
|
+
|
116
|
+
@queue.pop
|
117
|
+
|
118
|
+
expect(@queue.message_count).to eq(1)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context '#pop' do
|
123
|
+
|
124
|
+
it 'should return oldest message in queue' do
|
125
|
+
|
126
|
+
@queue.publish 'First'
|
127
|
+
@queue.publish 'Second'
|
128
|
+
|
129
|
+
expect(@queue.pop[:message]).to eq('First')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context '#purge' do
|
134
|
+
|
135
|
+
it 'should clear all messages' do
|
136
|
+
|
137
|
+
@queue.publish 'First'
|
138
|
+
@queue.publish 'Second'
|
139
|
+
|
140
|
+
@queue.purge
|
141
|
+
|
142
|
+
expect(@queue.message_count).to eq(0)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
describe BunnyMock::Session do
|
2
|
+
|
3
|
+
context '::new' do
|
4
|
+
|
5
|
+
it 'should start as not connected' do
|
6
|
+
|
7
|
+
expect(@session.status).to eq(:not_connected)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context '#start' do
|
12
|
+
|
13
|
+
it 'should set status to connected' do
|
14
|
+
|
15
|
+
expect(@session.start.status).to eq(:connected)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#stop (close)' do
|
20
|
+
|
21
|
+
it 'should set status to closed' do
|
22
|
+
|
23
|
+
@session.start
|
24
|
+
|
25
|
+
expect(@session.stop.status).to eq(:closed)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context '#open?' do
|
30
|
+
|
31
|
+
it 'should return true if status is open' do
|
32
|
+
|
33
|
+
@session.start
|
34
|
+
|
35
|
+
expect(@session.open?).to be_truthy
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should return false otherwise' do
|
39
|
+
|
40
|
+
# not_connected
|
41
|
+
expect(@session.open?).to be_falsey
|
42
|
+
|
43
|
+
@session.stop
|
44
|
+
|
45
|
+
# closed
|
46
|
+
expect(@session.open?).to be_falsey
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '#create_channel (channel)' do
|
51
|
+
|
52
|
+
it 'should create a new channel with no arguments' do
|
53
|
+
|
54
|
+
first = @session.create_channel
|
55
|
+
second = @session.create_channel
|
56
|
+
|
57
|
+
expect(first.class).to eq(BunnyMock::Channel)
|
58
|
+
expect(second.class).to eq(BunnyMock::Channel)
|
59
|
+
|
60
|
+
expect(first).to_not eq(second)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should return cached channel with same identifier' do
|
64
|
+
|
65
|
+
first = @session.create_channel 1
|
66
|
+
second = @session.create_channel 1
|
67
|
+
|
68
|
+
expect(first.class).to eq(BunnyMock::Channel)
|
69
|
+
expect(second.class).to eq(BunnyMock::Channel)
|
70
|
+
|
71
|
+
expect(first).to eq(second)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should return an ArgumentError for reserved channel' do
|
75
|
+
|
76
|
+
expect { @session.create_channel(0) }.to raise_error(ArgumentError)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
describe BunnyMock do
|
2
|
+
|
3
|
+
context '::new' do
|
4
|
+
|
5
|
+
it 'should return a new session' do
|
6
|
+
|
7
|
+
expect(BunnyMock.new.class).to eq(BunnyMock::Session)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context '::version' do
|
12
|
+
|
13
|
+
it 'should return the current version' do
|
14
|
+
|
15
|
+
expect(BunnyMock::VERSION).to_not be_nil
|
16
|
+
expect(BunnyMock.version).to_not be_nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '::protocol_version' do
|
21
|
+
|
22
|
+
it 'should return the current amq protocol version' do
|
23
|
+
|
24
|
+
expect(BunnyMock::PROTOCOL_VERSION).to eq('0.9.1')
|
25
|
+
expect(BunnyMock.protocol_version).to eq('0.9.1')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bunny-mock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Rempe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: amq-protocol
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.1
|
27
|
+
description: Easy to use mocking for testing the Bunny client for RabbitMQ
|
28
|
+
email:
|
29
|
+
- |
|
30
|
+
WVc1a2NtVjNjbVZ0Y0dWQVoyMWhhV3d1WTI5dFxu
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.md
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- ".rspec"
|
38
|
+
- ".travis.yml"
|
39
|
+
- ".yardopts"
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE
|
42
|
+
- README.md
|
43
|
+
- bunny-mock.gemspec
|
44
|
+
- lib/bunny-mock.rb
|
45
|
+
- lib/bunny_mock/channel.rb
|
46
|
+
- lib/bunny_mock/exchange.rb
|
47
|
+
- lib/bunny_mock/exchanges/direct.rb
|
48
|
+
- lib/bunny_mock/exchanges/fanout.rb
|
49
|
+
- lib/bunny_mock/exchanges/headers.rb
|
50
|
+
- lib/bunny_mock/exchanges/topic.rb
|
51
|
+
- lib/bunny_mock/queue.rb
|
52
|
+
- lib/bunny_mock/session.rb
|
53
|
+
- lib/bunny_mock/version.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- spec/unit/bunny_mock/channel_spec.rb
|
56
|
+
- spec/unit/bunny_mock/exchange_spec.rb
|
57
|
+
- spec/unit/bunny_mock/exchanges/direct_spec.rb
|
58
|
+
- spec/unit/bunny_mock/exchanges/fanout_spec.rb
|
59
|
+
- spec/unit/bunny_mock/exchanges/topic_spec.rb
|
60
|
+
- spec/unit/bunny_mock/queue_spec.rb
|
61
|
+
- spec/unit/bunny_mock/session_spec.rb
|
62
|
+
- spec/unit/bunny_mock_spec.rb
|
63
|
+
homepage:
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.6
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Mocking for the popular Bunny client for RabbitMQ
|
87
|
+
test_files:
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/unit/bunny_mock/channel_spec.rb
|
90
|
+
- spec/unit/bunny_mock/exchange_spec.rb
|
91
|
+
- spec/unit/bunny_mock/exchanges/direct_spec.rb
|
92
|
+
- spec/unit/bunny_mock/exchanges/fanout_spec.rb
|
93
|
+
- spec/unit/bunny_mock/exchanges/topic_spec.rb
|
94
|
+
- spec/unit/bunny_mock/queue_spec.rb
|
95
|
+
- spec/unit/bunny_mock/session_spec.rb
|
96
|
+
- spec/unit/bunny_mock_spec.rb
|
97
|
+
has_rdoc: true
|