celluloid_pubsub 0.0.20 → 0.0.21
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/celluloid_pubsub.gemspec +8 -8
- data/examples/simple_test.rb +2 -6
- data/lib/celluloid_pubsub/client_pubsub.rb +8 -6
- data/lib/celluloid_pubsub/version.rb +1 -1
- data/spec/lib/celluloid_pubsub/client_pubsub_spec.rb +17 -16
- data/spec/lib/celluloid_pubsub/reactor_spec.rb +214 -214
- data/spec/lib/celluloid_pubsub/registry_spec.rb +1 -1
- data/spec/lib/celluloid_pubsub/web_server_spec.rb +43 -43
- data/spec/spec_helper.rb +0 -2
- metadata +40 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9465c4977a3bc3e524ad74ede798b375706d2995
|
4
|
+
data.tar.gz: 488e312ddd2a283eb3c04ad688c7446c0af569ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c7e91caa3c87ba614eb92e585924690108b848c88b342cb83c41ee92d55cfa05cecebe04734a8fccc7dd98b2dfe35b75a5609cd1c186209635f6ffeb0e72c4a
|
7
|
+
data.tar.gz: 75fc469556285f61305268b7c0c17666d371da9636b7f236e7b287eef83022f009178216abb3537e7e2767db95c6442672c2454283420dbae8d3f0b28703a376
|
data/celluloid_pubsub.gemspec
CHANGED
@@ -22,21 +22,21 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_runtime_dependency 'celluloid-websocket-client', '0.0.1'
|
23
23
|
s.add_runtime_dependency 'activesupport', '~> 4.1', '>= 4.1.0'
|
24
24
|
|
25
|
-
s.add_development_dependency 'rspec-rails', '~>
|
26
|
-
s.add_development_dependency 'guard', '~> 2.
|
27
|
-
s.add_development_dependency 'guard-rspec', '~> 4.
|
28
|
-
s.add_development_dependency 'simplecov', '~> 0.
|
25
|
+
s.add_development_dependency 'rspec-rails', '~> 3.3', '>= 3.3'
|
26
|
+
s.add_development_dependency 'guard', '~> 2.13', '>= 2.13'
|
27
|
+
s.add_development_dependency 'guard-rspec', '~> 4.6', '>= 4.6'
|
28
|
+
s.add_development_dependency 'simplecov', '~> 0.10', '>= 0.10'
|
29
29
|
s.add_development_dependency 'simplecov-summary', '~> 0.0.4', '>= 0.0.4'
|
30
30
|
s.add_development_dependency 'mocha', '~> 1.1', '>= 1.1'
|
31
31
|
s.add_development_dependency 'coveralls', '~> 0.7', '>= 0.7'
|
32
32
|
s.add_development_dependency 'rvm-tester', '~> 1.1', '>= 1.1'
|
33
33
|
|
34
|
-
s.add_development_dependency 'rubocop', '0.
|
35
|
-
s.add_development_dependency 'phare', '~> 0.
|
34
|
+
s.add_development_dependency 'rubocop', '~> 0.33', '>= 0.33'
|
35
|
+
s.add_development_dependency 'phare', '~> 0.7', '>= 0.7'
|
36
36
|
s.add_development_dependency 'yard', '~> 0.8', '>= 0.8.7'
|
37
37
|
s.add_development_dependency 'yard-rspec', '~> 0.1', '>= 0.1'
|
38
|
-
s.add_development_dependency 'redcarpet', '~> 3.
|
38
|
+
s.add_development_dependency 'redcarpet', '~> 3.3', '>= 3.3'
|
39
39
|
s.add_development_dependency 'github-markup', '~> 1.3', '>= 1.3.3'
|
40
|
-
s.add_development_dependency 'inch', '~> 0.
|
40
|
+
s.add_development_dependency 'inch', '~> 0.6', '>= 0.6'
|
41
41
|
s.add_development_dependency 'guard-inch', '~> 0.1', '>= 0.1.0'
|
42
42
|
end
|
data/examples/simple_test.rb
CHANGED
@@ -19,9 +19,7 @@ class Subscriber
|
|
19
19
|
include Celluloid::Logger
|
20
20
|
|
21
21
|
def initialize(options = {})
|
22
|
-
@client = CelluloidPubsub::Client.connect({ actor: Actor.current }.merge(options))
|
23
|
-
ws.subscribe('test_channel') # this will execute after the connection is opened
|
24
|
-
end
|
22
|
+
@client = CelluloidPubsub::Client.connect({ actor: Actor.current, channel: 'test_channel' }.merge(options))
|
25
23
|
end
|
26
24
|
|
27
25
|
def on_message(message)
|
@@ -46,9 +44,7 @@ class Publisher
|
|
46
44
|
include Celluloid::Logger
|
47
45
|
|
48
46
|
def initialize(options = {})
|
49
|
-
@client = CelluloidPubsub::Client.connect({ actor: Actor.current }.merge(options))
|
50
|
-
ws.subscribe('test_channel2') # this will execute after the connection is opened
|
51
|
-
end
|
47
|
+
@client = CelluloidPubsub::Client.connect({ actor: Actor.current, channel: 'test_channel2' }.merge(options))
|
52
48
|
@client.publish('test_channel', 'data' => 'my_message') # the message needs to be a Hash
|
53
49
|
end
|
54
50
|
|
@@ -28,7 +28,7 @@ module CelluloidPubsub
|
|
28
28
|
class PubSubWorker
|
29
29
|
include Celluloid
|
30
30
|
include Celluloid::Logger
|
31
|
-
attr_accessor :actor, :
|
31
|
+
attr_accessor :actor, :client, :options, :hostname, :port, :path, :channel
|
32
32
|
|
33
33
|
# receives a list of options that are used to connect to the webserver and an actor to which the callbacks are delegated to
|
34
34
|
# when receiving messages from a channel
|
@@ -44,10 +44,10 @@ module CelluloidPubsub
|
|
44
44
|
# @return [void]
|
45
45
|
#
|
46
46
|
# @api public
|
47
|
-
def initialize(options
|
47
|
+
def initialize(options)
|
48
48
|
parse_options(options)
|
49
49
|
raise "#{self}: Please provide an actor in the options list!!!" if @actor.blank?
|
50
|
-
|
50
|
+
raise "#{self}: Please provide an channel in the options list!!!" if @channel.blank?
|
51
51
|
@client = Celluloid::WebSocket::Client.new("ws://#{@hostname}:#{@port}#{@path}", Actor.current)
|
52
52
|
end
|
53
53
|
|
@@ -66,6 +66,7 @@ module CelluloidPubsub
|
|
66
66
|
raise 'Options is not a hash' unless options.is_a?(Hash)
|
67
67
|
@options = options.stringify_keys!
|
68
68
|
@actor = @options.fetch('actor', nil)
|
69
|
+
@channel = @options.fetch('channel', nil)
|
69
70
|
@hostname = @options.fetch('hostname', CelluloidPubsub::WebServer::HOST)
|
70
71
|
@port = @options.fetch('port', CelluloidPubsub::WebServer::PORT)
|
71
72
|
@path = @options.fetch('path', CelluloidPubsub::WebServer::PATH)
|
@@ -147,6 +148,7 @@ module CelluloidPubsub
|
|
147
148
|
def unsubscribe_all
|
148
149
|
send_action('unsubscribe_all')
|
149
150
|
end
|
151
|
+
|
150
152
|
# callback executes after connection is opened and delegates action to actor
|
151
153
|
#
|
152
154
|
# @return [void]
|
@@ -154,7 +156,7 @@ module CelluloidPubsub
|
|
154
156
|
# @api public
|
155
157
|
def on_open
|
156
158
|
debug("#{self.class} websocket connection opened") if debug_enabled?
|
157
|
-
@
|
159
|
+
async.subscribe(@channel)
|
158
160
|
end
|
159
161
|
|
160
162
|
# callback executes when actor receives a message from a subscribed channel
|
@@ -245,8 +247,8 @@ module CelluloidPubsub
|
|
245
247
|
# @return [CelluloidPubsub::Client::PubSubWorker]
|
246
248
|
#
|
247
249
|
# @api public
|
248
|
-
def self.connect(options = {}
|
249
|
-
CelluloidPubsub::Client::PubSubWorker.new(options
|
250
|
+
def self.connect(options = {})
|
251
|
+
CelluloidPubsub::Client::PubSubWorker.new(options)
|
250
252
|
end
|
251
253
|
end
|
252
254
|
end
|
@@ -10,7 +10,7 @@ describe CelluloidPubsub::Client do
|
|
10
10
|
expected = nil
|
11
11
|
CelluloidPubsub::Client::PubSubWorker.stubs(:new).returns(expected)
|
12
12
|
res = CelluloidPubsub::Client.connect(options, &blk)
|
13
|
-
res.
|
13
|
+
expect(res).to eq expected
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -19,11 +19,12 @@ describe CelluloidPubsub::Client::PubSubWorker do
|
|
19
19
|
let(:options) { {} }
|
20
20
|
let(:socket) { mock }
|
21
21
|
let(:actor) { mock }
|
22
|
+
let(:channel) { 'some_channel' }
|
22
23
|
|
23
24
|
before(:each) do
|
24
25
|
Celluloid::WebSocket::Client.stubs(:new).returns(socket)
|
25
26
|
socket.stubs(:text)
|
26
|
-
@worker = CelluloidPubsub::Client::PubSubWorker.new({ 'actor' => actor, enable_debug: true }, &blk)
|
27
|
+
@worker = CelluloidPubsub::Client::PubSubWorker.new({ 'actor' => actor, channel: channel, enable_debug: true }, &blk)
|
27
28
|
@worker.stubs(:client).returns(socket)
|
28
29
|
@worker.stubs(:debug)
|
29
30
|
@worker.stubs(:async).returns(@worker)
|
@@ -32,8 +33,8 @@ describe CelluloidPubsub::Client::PubSubWorker do
|
|
32
33
|
|
33
34
|
describe '#initialize' do
|
34
35
|
it 'creates a object' do
|
35
|
-
@worker.
|
36
|
-
@worker.actor.
|
36
|
+
expect(@worker.channel).to eq channel
|
37
|
+
expect(@worker.actor).to eq actor
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -46,25 +47,25 @@ describe CelluloidPubsub::Client::PubSubWorker do
|
|
46
47
|
|
47
48
|
it 'parses options' do
|
48
49
|
@worker.parse_options(custom_options)
|
49
|
-
@worker.actor.
|
50
|
-
@worker.hostname.
|
51
|
-
@worker.port.
|
52
|
-
@worker.path.
|
50
|
+
expect(@worker.actor).to eq(actor)
|
51
|
+
expect(@worker.hostname).to eq(hostname)
|
52
|
+
expect(@worker.port).to eq(port)
|
53
|
+
expect(@worker.path).to eq(path)
|
53
54
|
end
|
54
55
|
|
55
56
|
it 'sets defaults' do
|
56
57
|
@worker.parse_options({})
|
57
|
-
@worker.actor.
|
58
|
-
@worker.hostname.
|
59
|
-
@worker.port.
|
60
|
-
@worker.path.
|
58
|
+
expect(@worker.actor).to eq(nil)
|
59
|
+
expect(@worker.hostname).to eq('0.0.0.0')
|
60
|
+
expect(@worker.port).to eq(1234)
|
61
|
+
expect(@worker.path).to eq('/ws')
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
64
65
|
describe '#debug_enabled?' do
|
65
66
|
it 'checks if debug is enabled' do
|
66
67
|
act = @worker.debug_enabled?
|
67
|
-
act.
|
68
|
+
expect(act).to eq(true)
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
@@ -89,14 +90,14 @@ describe CelluloidPubsub::Client::PubSubWorker do
|
|
89
90
|
message.expects(:present?).returns(true)
|
90
91
|
message.stubs(:[]).with('client_action').returns('successful_subscription')
|
91
92
|
actual = @worker.succesfull_subscription?(message)
|
92
|
-
actual.
|
93
|
+
expect(actual).to eq(true)
|
93
94
|
end
|
94
95
|
|
95
96
|
it 'checks the message and returns false' do
|
96
97
|
message.expects(:present?).returns(true)
|
97
98
|
message.stubs(:[]).with('client_action').returns('something_else')
|
98
99
|
actual = @worker.succesfull_subscription?(message)
|
99
|
-
actual.
|
100
|
+
expect(actual).to eq(false)
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
@@ -113,7 +114,7 @@ describe CelluloidPubsub::Client::PubSubWorker do
|
|
113
114
|
let(:channel) { 'some_channel' }
|
114
115
|
let(:data) { 'some_message' }
|
115
116
|
it 'chats with the server' do
|
116
|
-
@worker.
|
117
|
+
@worker.expects(:subscribe).with(channel)
|
117
118
|
@worker.on_open
|
118
119
|
end
|
119
120
|
end
|
@@ -1,214 +1,214 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
1
|
+
# encoding:utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe CelluloidPubsub::Reactor do
|
6
|
+
let(:websocket) { mock }
|
7
|
+
let(:server) { mock }
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
subject.stubs(:async).returns(subject)
|
11
|
+
server.stubs(:debug_enabled?).returns(false)
|
12
|
+
server.stubs(:async).returns(server)
|
13
|
+
server.stubs(:handle_dispatched_message)
|
14
|
+
server.stubs(:subscribers).returns({})
|
15
|
+
websocket.stubs(:read)
|
16
|
+
subject.stubs(:inspect).returns(subject)
|
17
|
+
subject.stubs(:run)
|
18
|
+
subject.work(websocket, server)
|
19
|
+
subject.stubs(:unsubscribe_from_channel).returns(true)
|
20
|
+
Celluloid::Actor.stubs(:kill).returns(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#work' do
|
24
|
+
it 'works ' do
|
25
|
+
subject.expects(:run)
|
26
|
+
subject.work(websocket, server)
|
27
|
+
expect(subject.websocket).to eq websocket
|
28
|
+
expect(subject.server).to eq server
|
29
|
+
expect(subject.channels).to eq []
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# describe '#rub' do
|
34
|
+
# let(:data) { 'some message' }
|
35
|
+
#
|
36
|
+
# it 'works ' do
|
37
|
+
# subject.unstub(:run)
|
38
|
+
# websocket.stubs(:read).returns(data)
|
39
|
+
# subject.expects(:handle_websocket_message).with(data)
|
40
|
+
# subject.run
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
|
44
|
+
describe '#parse_json_data' do
|
45
|
+
let(:data) { 'some message' }
|
46
|
+
let(:expected) { data.to_json }
|
47
|
+
|
48
|
+
it 'works with hash ' do
|
49
|
+
JSON.expects(:parse).with(data).returns(expected)
|
50
|
+
actual = subject.parse_json_data(data)
|
51
|
+
expect(actual).to eq expected
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'works with exception parsing ' do
|
55
|
+
JSON.expects(:parse).with(data).raises(StandardError)
|
56
|
+
actual = subject.parse_json_data(data)
|
57
|
+
expect(actual).to eq data
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#handle_websocket_message' do
|
62
|
+
let(:data) { 'some message' }
|
63
|
+
let(:json_data) { { a: 'b' } }
|
64
|
+
|
65
|
+
it 'handle_websocket_message' do
|
66
|
+
subject.expects(:parse_json_data).with(data).returns(json_data)
|
67
|
+
subject.expects(:handle_parsed_websocket_message).with(json_data)
|
68
|
+
subject.handle_websocket_message(data)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#handle_parsed_websocket_message' do
|
73
|
+
it 'handle_websocket_message with a hash' do
|
74
|
+
data = { 'client_action' => 'b' }
|
75
|
+
data.expects(:stringify_keys).returns(data)
|
76
|
+
subject.expects(:delegate_action).with(data)
|
77
|
+
subject.handle_parsed_websocket_message(data)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'handle_websocket_message with something else than a hash' do
|
81
|
+
data = 'some message'
|
82
|
+
subject.expects(:handle_unknown_action).with(data)
|
83
|
+
subject.handle_parsed_websocket_message(data)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#delegate_action' do
|
88
|
+
it 'unsubscribes all' do
|
89
|
+
data = { 'client_action' => 'unsubscribe_all' }
|
90
|
+
subject.expects(:unsubscribe_all).returns('bla')
|
91
|
+
subject.delegate_action(data)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'unsubscribes all' do
|
95
|
+
data = { 'client_action' => 'unsubscribe', 'channel' => 'some channel' }
|
96
|
+
subject.expects(:unsubscribe).with(data['channel'])
|
97
|
+
subject.delegate_action(data)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'subscribes to channell' do
|
101
|
+
data = { 'client_action' => 'subscribe', 'channel' => 'some channel' }
|
102
|
+
subject.expects(:start_subscriber).with(data['channel'], data)
|
103
|
+
subject.delegate_action(data)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'publish' do
|
107
|
+
data = { 'client_action' => 'publish', 'channel' => 'some channel', 'data' => 'some data' }
|
108
|
+
server.expects(:publish_event).with(data['channel'], data['data'].to_json)
|
109
|
+
subject.delegate_action(data)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'handles unknown' do
|
113
|
+
data = { 'client_action' => 'some action', 'channel' => 'some channel' }
|
114
|
+
subject.expects(:handle_unknown_action).with(data)
|
115
|
+
subject.delegate_action(data)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#handle_unknown_action' do
|
120
|
+
it 'handles unknown' do
|
121
|
+
data = 'some data'
|
122
|
+
server.expects(:handle_dispatched_message)
|
123
|
+
subject.handle_unknown_action(data)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#unsubscribe_client' do
|
128
|
+
let(:channel) { 'some channel' }
|
129
|
+
it 'returns nil' do
|
130
|
+
act = subject.unsubscribe('')
|
131
|
+
expect(act).to eq(nil)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'unsubscribes' do
|
135
|
+
subject.channels.stubs(:blank?).returns(false)
|
136
|
+
subject.channels.expects(:delete).with(channel)
|
137
|
+
act = subject.unsubscribe(channel)
|
138
|
+
expect(act).to eq(nil)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'unsubscribes' do
|
142
|
+
subject.channels.stubs(:blank?).returns(true)
|
143
|
+
subject.websocket.expects(:close)
|
144
|
+
act = subject.unsubscribe(channel)
|
145
|
+
expect(act).to eq(nil)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'unsubscribes' do
|
149
|
+
subject.channels.stubs(:blank?).returns(false)
|
150
|
+
subject.channels.stubs(:delete)
|
151
|
+
server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
|
152
|
+
subject.unsubscribe(channel)
|
153
|
+
expect(server.subscribers[channel]).to eq([])
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#shutdown' do
|
158
|
+
it 'shutdowns' do
|
159
|
+
subject.expects(:terminate)
|
160
|
+
subject.shutdown
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#start_subscriber' do
|
165
|
+
let(:channel) { 'some channel' }
|
166
|
+
let(:message) { { a: 'b' } }
|
167
|
+
|
168
|
+
it 'subscribes ' do
|
169
|
+
act = subject.start_subscriber('', message)
|
170
|
+
expect(act).to eq(nil)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'subscribes ' do
|
174
|
+
subject.stubs(:add_subscriber_to_channel).with(channel, message)
|
175
|
+
subject.websocket.expects(:<<).with(message.merge('client_action' => 'successful_subscription', 'channel' => channel).to_json)
|
176
|
+
subject.start_subscriber(channel, message)
|
177
|
+
end
|
178
|
+
|
179
|
+
# it 'raises error' do
|
180
|
+
# subject.stubs(:add_subscriber_to_channel).raises(StandardError)
|
181
|
+
#
|
182
|
+
# expect do
|
183
|
+
# subject.start_subscriber(channel, message)
|
184
|
+
# end.to raise_error(StandardError) { |e|
|
185
|
+
# expect(e.message).to include(channel)
|
186
|
+
# }
|
187
|
+
# end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe '#add_subscriber_to_channel' do
|
191
|
+
let(:channel) { 'some channel' }
|
192
|
+
let(:message) { { a: 'b' } }
|
193
|
+
|
194
|
+
it 'adds subscribed' do
|
195
|
+
CelluloidPubsub::Registry.channels.stubs(:include?).with(channel).returns(false)
|
196
|
+
CelluloidPubsub::Registry.channels.expects(:<<).with(channel)
|
197
|
+
server.subscribers[channel] = []
|
198
|
+
server.subscribers[channel].expects(:<<).with(reactor: subject, message: message)
|
199
|
+
subject.add_subscriber_to_channel(channel, message)
|
200
|
+
expect(subject.channels).to include(channel)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe '#unsubscribe_all' do
|
205
|
+
let(:channel) { 'some channel' }
|
206
|
+
let(:message) { { a: 'b' } }
|
207
|
+
|
208
|
+
it 'adds subscribed' do
|
209
|
+
CelluloidPubsub::Registry.stubs(:channels).returns([channel])
|
210
|
+
subject.expects(:unsubscribe_from_channel).with(channel)
|
211
|
+
subject.unsubscribe_all
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
|
1
|
+
# encoding:utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
describe CelluloidPubsub::WebServer do
|
6
|
+
it 'should have host constant' do
|
7
|
+
expect(CelluloidPubsub::WebServer::HOST).to eq('0.0.0.0')
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
it 'should have host constant' do
|
11
|
+
expect(CelluloidPubsub::WebServer::PORT).to eq(1234)
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
it 'should have host constant' do
|
15
|
+
expect(CelluloidPubsub::WebServer::PATH).to eq('/ws')
|
16
|
+
end
|
17
|
+
let(:options) { {} }
|
18
|
+
let(:web_server) { mock }
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
before(:each) do
|
21
|
+
CelluloidPubsub::WebServer.stubs(:new).returns(web_server)
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
24
|
+
# it '#initialize with default values ' do
|
25
|
+
# web_server.parse_options({})
|
26
|
+
# web_server.hostname.should eq(CelluloidPubsub::WebServer::HOST)
|
27
|
+
# web_server.port.should eq(CelluloidPubsub::WebServer::PORT)
|
28
|
+
# web_server.path.should eq(CelluloidPubsub::WebServer::PATH)
|
29
|
+
# web_server.backlog.should eq(1024)
|
30
|
+
# web_server.spy.should eq(false)
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# describe '#with custom values' do
|
34
|
+
# let(:hostname) { '192.0.0.1' }
|
35
|
+
# let(:port) { 13_456 }
|
36
|
+
# let(:path) { '/pathy' }
|
37
|
+
# let(:backlog) { 2048 }
|
38
|
+
# let(:spy) { true }
|
39
|
+
#
|
40
|
+
# it '#initialize with custom values ' do
|
41
|
+
# web_server.parse_options(hostname: hostname, port: port, path: path, spy: spy, backlog: backlog)
|
42
|
+
# web_server.hostname.should eq(hostname)
|
43
|
+
# web_server.port.should eq(port)
|
44
|
+
# web_server.path.should eq(path)
|
45
|
+
# web_server.backlog.should eq(backlog)
|
46
|
+
# web_server.spy.should eq(spy)
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid_pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bogdanRada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -110,80 +110,80 @@ dependencies:
|
|
110
110
|
requirements:
|
111
111
|
- - "~>"
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: '
|
113
|
+
version: '3.3'
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '3.3'
|
117
117
|
type: :development
|
118
118
|
prerelease: false
|
119
119
|
version_requirements: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
123
|
+
version: '3.3'
|
124
124
|
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version: '
|
126
|
+
version: '3.3'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: guard
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
131
|
- - "~>"
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: '2.
|
133
|
+
version: '2.13'
|
134
134
|
- - ">="
|
135
135
|
- !ruby/object:Gem::Version
|
136
|
-
version: '2.
|
136
|
+
version: '2.13'
|
137
137
|
type: :development
|
138
138
|
prerelease: false
|
139
139
|
version_requirements: !ruby/object:Gem::Requirement
|
140
140
|
requirements:
|
141
141
|
- - "~>"
|
142
142
|
- !ruby/object:Gem::Version
|
143
|
-
version: '2.
|
143
|
+
version: '2.13'
|
144
144
|
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: '2.
|
146
|
+
version: '2.13'
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: guard-rspec
|
149
149
|
requirement: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
151
|
- - "~>"
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version: '4.
|
153
|
+
version: '4.6'
|
154
154
|
- - ">="
|
155
155
|
- !ruby/object:Gem::Version
|
156
|
-
version: '4.
|
156
|
+
version: '4.6'
|
157
157
|
type: :development
|
158
158
|
prerelease: false
|
159
159
|
version_requirements: !ruby/object:Gem::Requirement
|
160
160
|
requirements:
|
161
161
|
- - "~>"
|
162
162
|
- !ruby/object:Gem::Version
|
163
|
-
version: '4.
|
163
|
+
version: '4.6'
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '4.
|
166
|
+
version: '4.6'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: simplecov
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: '0.
|
173
|
+
version: '0.10'
|
174
174
|
- - ">="
|
175
175
|
- !ruby/object:Gem::Version
|
176
|
-
version: '0.
|
176
|
+
version: '0.10'
|
177
177
|
type: :development
|
178
178
|
prerelease: false
|
179
179
|
version_requirements: !ruby/object:Gem::Requirement
|
180
180
|
requirements:
|
181
181
|
- - "~>"
|
182
182
|
- !ruby/object:Gem::Version
|
183
|
-
version: '0.
|
183
|
+
version: '0.10'
|
184
184
|
- - ">="
|
185
185
|
- !ruby/object:Gem::Version
|
186
|
-
version: '0.
|
186
|
+
version: '0.10'
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: simplecov-summary
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -268,36 +268,42 @@ dependencies:
|
|
268
268
|
name: rubocop
|
269
269
|
requirement: !ruby/object:Gem::Requirement
|
270
270
|
requirements:
|
271
|
-
- -
|
271
|
+
- - "~>"
|
272
|
+
- !ruby/object:Gem::Version
|
273
|
+
version: '0.33'
|
274
|
+
- - ">="
|
272
275
|
- !ruby/object:Gem::Version
|
273
|
-
version: '0.
|
276
|
+
version: '0.33'
|
274
277
|
type: :development
|
275
278
|
prerelease: false
|
276
279
|
version_requirements: !ruby/object:Gem::Requirement
|
277
280
|
requirements:
|
278
|
-
- -
|
281
|
+
- - "~>"
|
279
282
|
- !ruby/object:Gem::Version
|
280
|
-
version: '0.
|
283
|
+
version: '0.33'
|
284
|
+
- - ">="
|
285
|
+
- !ruby/object:Gem::Version
|
286
|
+
version: '0.33'
|
281
287
|
- !ruby/object:Gem::Dependency
|
282
288
|
name: phare
|
283
289
|
requirement: !ruby/object:Gem::Requirement
|
284
290
|
requirements:
|
285
291
|
- - "~>"
|
286
292
|
- !ruby/object:Gem::Version
|
287
|
-
version: '0.
|
293
|
+
version: '0.7'
|
288
294
|
- - ">="
|
289
295
|
- !ruby/object:Gem::Version
|
290
|
-
version: '0.
|
296
|
+
version: '0.7'
|
291
297
|
type: :development
|
292
298
|
prerelease: false
|
293
299
|
version_requirements: !ruby/object:Gem::Requirement
|
294
300
|
requirements:
|
295
301
|
- - "~>"
|
296
302
|
- !ruby/object:Gem::Version
|
297
|
-
version: '0.
|
303
|
+
version: '0.7'
|
298
304
|
- - ">="
|
299
305
|
- !ruby/object:Gem::Version
|
300
|
-
version: '0.
|
306
|
+
version: '0.7'
|
301
307
|
- !ruby/object:Gem::Dependency
|
302
308
|
name: yard
|
303
309
|
requirement: !ruby/object:Gem::Requirement
|
@@ -344,20 +350,20 @@ dependencies:
|
|
344
350
|
requirements:
|
345
351
|
- - "~>"
|
346
352
|
- !ruby/object:Gem::Version
|
347
|
-
version: '3.
|
353
|
+
version: '3.3'
|
348
354
|
- - ">="
|
349
355
|
- !ruby/object:Gem::Version
|
350
|
-
version: 3.
|
356
|
+
version: '3.3'
|
351
357
|
type: :development
|
352
358
|
prerelease: false
|
353
359
|
version_requirements: !ruby/object:Gem::Requirement
|
354
360
|
requirements:
|
355
361
|
- - "~>"
|
356
362
|
- !ruby/object:Gem::Version
|
357
|
-
version: '3.
|
363
|
+
version: '3.3'
|
358
364
|
- - ">="
|
359
365
|
- !ruby/object:Gem::Version
|
360
|
-
version: 3.
|
366
|
+
version: '3.3'
|
361
367
|
- !ruby/object:Gem::Dependency
|
362
368
|
name: github-markup
|
363
369
|
requirement: !ruby/object:Gem::Requirement
|
@@ -384,20 +390,20 @@ dependencies:
|
|
384
390
|
requirements:
|
385
391
|
- - "~>"
|
386
392
|
- !ruby/object:Gem::Version
|
387
|
-
version: '0.
|
393
|
+
version: '0.6'
|
388
394
|
- - ">="
|
389
395
|
- !ruby/object:Gem::Version
|
390
|
-
version: 0.
|
396
|
+
version: '0.6'
|
391
397
|
type: :development
|
392
398
|
prerelease: false
|
393
399
|
version_requirements: !ruby/object:Gem::Requirement
|
394
400
|
requirements:
|
395
401
|
- - "~>"
|
396
402
|
- !ruby/object:Gem::Version
|
397
|
-
version: '0.
|
403
|
+
version: '0.6'
|
398
404
|
- - ">="
|
399
405
|
- !ruby/object:Gem::Version
|
400
|
-
version: 0.
|
406
|
+
version: '0.6'
|
401
407
|
- !ruby/object:Gem::Dependency
|
402
408
|
name: guard-inch
|
403
409
|
requirement: !ruby/object:Gem::Requirement
|