celluloid_pubsub 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +2 -2
  4. data/Rakefile +6 -3
  5. data/celluloid_pubsub.gemspec +1 -1
  6. data/lib/celluloid_pubsub/reactor.rb +11 -15
  7. data/lib/celluloid_pubsub/version.rb +1 -1
  8. data/lib/celluloid_pubsub/web_server.rb +3 -0
  9. data/spec/lib/celluloid_pubsub/client_pubsub_spec.rb +128 -0
  10. data/spec/lib/celluloid_pubsub/reactor_spec.rb +208 -0
  11. data/spec/lib/celluloid_pubsub/registry_spec.rb +4 -0
  12. data/spec/lib/celluloid_pubsub/web_server_spec.rb +43 -0
  13. data/spec/spec_helper.rb +8 -0
  14. metadata +12 -70
  15. data/bin/appraisal +0 -16
  16. data/bin/autospec +0 -16
  17. data/bin/bundler +0 -16
  18. data/bin/cdiff +0 -16
  19. data/bin/coderay +0 -16
  20. data/bin/colortab +0 -16
  21. data/bin/coveralls +0 -16
  22. data/bin/decolor +0 -16
  23. data/bin/erubis +0 -16
  24. data/bin/guard +0 -16
  25. data/bin/htmldiff +0 -16
  26. data/bin/inch +0 -16
  27. data/bin/ldiff +0 -16
  28. data/bin/listen +0 -16
  29. data/bin/nokogiri +0 -16
  30. data/bin/phare +0 -16
  31. data/bin/pry +0 -16
  32. data/bin/rackup +0 -16
  33. data/bin/rails +0 -16
  34. data/bin/rake +0 -16
  35. data/bin/restclient +0 -16
  36. data/bin/rspec +0 -16
  37. data/bin/rubocop +0 -16
  38. data/bin/ruby-parse +0 -16
  39. data/bin/ruby-rewrite +0 -16
  40. data/bin/sass +0 -16
  41. data/bin/sass-convert +0 -16
  42. data/bin/scss +0 -16
  43. data/bin/scss-lint +0 -16
  44. data/bin/sparkr +0 -16
  45. data/bin/term_display +0 -16
  46. data/bin/term_mandel +0 -16
  47. data/bin/thor +0 -16
  48. data/bin/yard +0 -16
  49. data/bin/yardoc +0 -16
  50. data/bin/yardstick +0 -16
  51. data/bin/yri +0 -16
  52. data/doc/CelluloidPubsub/Client/PubSubWorker.html +0 -3676
  53. data/doc/CelluloidPubsub/Client.html +0 -340
  54. data/doc/CelluloidPubsub/Reactor.html +0 -3502
  55. data/doc/CelluloidPubsub/Registry.html +0 -234
  56. data/doc/CelluloidPubsub/VERSION.html +0 -204
  57. data/doc/CelluloidPubsub/WebServer.html +0 -4275
  58. data/doc/CelluloidPubsub.html +0 -225
  59. data/doc/_index.html +0 -184
  60. data/doc/class_list.html +0 -58
  61. data/doc/css/common.css +0 -1
  62. data/doc/css/full_list.css +0 -57
  63. data/doc/css/style.css +0 -339
  64. data/doc/file.README.html +0 -150
  65. data/doc/file_list.html +0 -60
  66. data/doc/frames.html +0 -26
  67. data/doc/index.html +0 -150
  68. data/doc/js/app.js +0 -219
  69. data/doc/js/full_list.js +0 -181
  70. data/doc/js/jquery.js +0 -4
  71. data/doc/method_list.html +0 -357
  72. data/doc/top-level-namespace.html +0 -112
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e37179d0afaad2f44c4b8e6d24fab235586cde36
4
- data.tar.gz: a44ccf96280f12254beaa58a4694720945a16f1b
3
+ metadata.gz: 2e2bb403ba535ddc3097815566d5d19936ea86e1
4
+ data.tar.gz: 4919d72301e1b6bd5afb05742a28e897cbd0b194
5
5
  SHA512:
6
- metadata.gz: f5592c3b5661b3c5e4a1c808e47c7f6340377e02a245b5de43ae612219cd2e833d3e3a4194b9dff3f8102692ee34a775872e3d8b5c48c5f254025bd561d5cd0d
7
- data.tar.gz: 3251df4e8410b870d6a0ee5c02e837d58c279257035c15db294615cbf418a3f16359ddc24dbbb0b170cc0565db615501da951fe820277e8f7f5178c42b55600f
6
+ metadata.gz: 830e2d740aec3fe17a899f1623f0a7a4844ac9fe69348df0b3ce335f4a27decf0dea5af19039259da9dc3875061a1d6017aec676bda51003eab6d6c006cb4421
7
+ data.tar.gz: 558c3876da55ee779fea5d336f984fff2163b8420dae64a95b4680950eb9931db5ce6b551a2464250fe01987b0af55bceadfa8fb664c059f7efd46fbc78a3a30
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ Gemfile.lock
15
15
  /nbproject/
16
16
  /.git-rewrite/
17
17
  .yardoc/
18
+ doc/
19
+ bin/
data/.travis.yml CHANGED
@@ -5,9 +5,9 @@ before_install:
5
5
  rvm:
6
6
  - 1.9.3
7
7
  - 2.0.0
8
- - 2.1
8
+ - 2.1.5
9
9
  - 2.2
10
10
  env:
11
11
  - RAILS_ENV=test RACK_ENV=test
12
12
  notifications:
13
- email: false
13
+ email: false
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require 'bundler/gem_tasks'
3
3
  require 'rspec/core/rake_task'
4
4
  require 'coveralls/rake/task'
5
5
  require 'yard'
6
+ require 'yard-rspec'
6
7
  Coveralls::RakeTask.new
7
8
 
8
9
  RSpec::Core::RakeTask.new(:spec) do |spec|
@@ -16,10 +17,12 @@ end
16
17
  # Dummy::Application.load_tasks
17
18
  # Rake::Task["db:test:prepare"].invoke
18
19
  # end
20
+ YARD::Config.options[:load_plugins] = true
21
+ YARD::Config.load_plugins
19
22
 
20
23
  YARD::Rake::YardocTask.new do |t|
21
- t.files = ['lib/**/*.rb'] # optional
22
- t.options = ['--any', '--extra', '--opts', '--markup-provider=redcarpet', '--markup=markdown'] # optional
24
+ t.files = ['lib/**/*.rb', 'spec/**/*_spec.rb'] # optional
25
+ t.options = ['--any', '--extra', '--opts', '--markup-provider=redcarpet', '--markup=markdown', '--debug'] # optional
23
26
  t.stats_options = ['--list-undoc'] # optional
24
27
  end
25
28
 
@@ -44,7 +47,7 @@ task :all do |_t|
44
47
  if ENV['TRAVIS']
45
48
  exec(' bundle exec phare && bundle exec rake spec && bundle exec rake coveralls:push')
46
49
  else
47
- exec('bundle exec phare && bundle exec rake spec')
50
+ exec('bundle exec rubocop -a . && bundle exec phare && bundle exec rake spec')
48
51
  end
49
52
  end
50
53
 
@@ -33,8 +33,8 @@ Gem::Specification.new do |s|
33
33
 
34
34
  s.add_development_dependency 'rubocop', '0.29'
35
35
  s.add_development_dependency 'phare', '~> 0.6', '>= 0.6'
36
- s.add_development_dependency 'scss-lint', '~> 0.34', '>= 0.34'
37
36
  s.add_development_dependency 'yard', '~> 0.8.7', '>= 0.8.7'
37
+ s.add_development_dependency 'yard-rspec', '~> 0.1', '>= 0.1'
38
38
  s.add_development_dependency 'redcarpet', '~> 3.2.2', '>= 3.2.2'
39
39
  s.add_development_dependency 'github-markup', '~> 1.3.3', '>= 1.3.3'
40
40
  s.add_development_dependency 'inch', '~> 0.5.10'
@@ -2,15 +2,13 @@ require_relative './registry'
2
2
  module CelluloidPubsub
3
3
  # The reactor handles new connections. Based on what the client sends it either subscribes to a channel
4
4
  # or will publish to a channel or just dispatch to the server if command is neither subscribe, publish or unsubscribe
5
+ #
5
6
  # @!attribute websocket
6
7
  # @return [Reel::WebSocket] websocket connection
7
8
  #
8
9
  # @!attribute server
9
10
  # @return [CelluloidPubsub::Webserver] the server actor to which the reactor is connected to
10
11
  #
11
- # @!attribute mutex
12
- # @return [Mutex] mutex used to lock when subscribing to a channel
13
- #
14
12
  # @!attribute channels
15
13
  # @return [Array] array of channels to which the current reactor has subscribed to
16
14
  class Reactor
@@ -18,10 +16,10 @@ module CelluloidPubsub
18
16
  include Celluloid::IO
19
17
  include Celluloid::Logger
20
18
 
21
- attr_accessor :websocket, :server, :mutex, :channels
19
+ attr_accessor :websocket, :server, :channels
22
20
 
23
21
  # rececives a new socket connection from the server
24
- # and initiates a new mutex that can be used when subsribing to a channel
22
+ # and listens for messages
25
23
  #
26
24
  # @param [Reel::WebSocket] websocket
27
25
  #
@@ -30,7 +28,6 @@ module CelluloidPubsub
30
28
  # @api public
31
29
  def work(websocket, server)
32
30
  @server = server
33
- @mutex = Mutex.new
34
31
  @channels = []
35
32
  @websocket = websocket
36
33
  info "Streaming changes for #{websocket.url}" if @server.debug_enabled?
@@ -44,11 +41,14 @@ module CelluloidPubsub
44
41
  # @return [void]
45
42
  #
46
43
  # @api public
44
+ #
45
+ # :nocov:
47
46
  def run
48
47
  while message = @websocket.read
49
48
  handle_websocket_message(message)
50
49
  end
51
50
  end
51
+ # :nocov:
52
52
 
53
53
  # method used to parse a JSON object into a Hash object
54
54
  #
@@ -170,11 +170,11 @@ module CelluloidPubsub
170
170
  # @api public
171
171
  def unsubscribe_client(channel)
172
172
  return unless channel.present?
173
- @channels.delete(channel)
173
+ @channels.delete(channel) unless @channels.blank?
174
174
  @websocket.close if @channels.blank?
175
175
  @server.subscribers[channel].delete_if do |hash|
176
176
  hash[:reactor] == Actor.current
177
- end
177
+ end if @server.subscribers[channel].present?
178
178
  end
179
179
 
180
180
  # the method will terminate the current actor
@@ -200,13 +200,9 @@ module CelluloidPubsub
200
200
  # @api public
201
201
  def start_subscriber(channel, message)
202
202
  return unless channel.present?
203
- begin
204
- add_subscriber_to_channel(channel, message)
205
- debug "Subscribed to #{channel} with #{message}" if @server.debug_enabled?
206
- @websocket << message.merge('client_action' => 'successful_subscription', 'channel' => channel).to_json
207
- rescue => e
208
- raise [e, e.respond_to?(:backtrace) ? e.backtrace : '', channel, message].inspect
209
- end
203
+ add_subscriber_to_channel(channel, message)
204
+ debug "Subscribed to #{channel} with #{message}" if @server.debug_enabled?
205
+ @websocket << message.merge('client_action' => 'successful_subscription', 'channel' => channel).to_json
210
206
  end
211
207
 
212
208
  # adds the curent actor the list of the subscribers for a particular channel
@@ -17,7 +17,7 @@ module CelluloidPubsub
17
17
  # minor release version
18
18
  MINOR = 0
19
19
  # tiny release version
20
- TINY = 8
20
+ TINY = 9
21
21
  # prelease version ( set this only if it is a prelease)
22
22
  PRE = nil
23
23
 
@@ -51,12 +51,15 @@ module CelluloidPubsub
51
51
  # @return [void]
52
52
  #
53
53
  # @api public
54
+ #
55
+ # :nocov:
54
56
  def initialize(options = {})
55
57
  parse_options(options)
56
58
  @subscribers = {}
57
59
  info "CelluloidPubsub::WebServer example starting on #{@hostname}:#{@port}" if debug_enabled?
58
60
  super(@hostname, @port, { spy: @spy, backlog: @backlog }, &method(:on_connection))
59
61
  end
62
+ # :nocov:
60
63
 
61
64
  # receives a list of options that are used to configure the webserver
62
65
  #
@@ -3,7 +3,135 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe CelluloidPubsub::Client do
6
+ let(:options) { {} }
7
+ let(:blk) { proc { |a| puts a } }
8
+
9
+ it 'runs the connect method' do
10
+ expected = nil
11
+ CelluloidPubsub::Client::PubSubWorker.stubs(:new).returns(expected)
12
+ res = CelluloidPubsub::Client.connect(options, &blk)
13
+ res.should eq expected
14
+ end
6
15
  end
7
16
 
8
17
  describe CelluloidPubsub::Client::PubSubWorker do
18
+ let(:blk) { proc { |a| puts a } }
19
+ let(:options) { {} }
20
+ let(:socket) { mock }
21
+ let(:actor) { mock }
22
+
23
+ before(:each) do
24
+ Celluloid::WebSocket::Client.stubs(:new).returns(socket)
25
+ socket.stubs(:text)
26
+ @worker = CelluloidPubsub::Client::PubSubWorker.new({ 'actor' => actor }, &blk)
27
+ @worker.stubs(:client).returns(socket)
28
+ @worker.stubs(:debug)
29
+ @worker.stubs(:async).returns(@worker)
30
+ actor.stubs(:async).returns(actor)
31
+ end
32
+
33
+ describe '#initialize' do
34
+ it 'creates a object' do
35
+ @worker.connect_blk.should_not be_nil
36
+ @worker.actor.should eq actor
37
+ end
38
+ end
39
+
40
+ describe '#parse_options' do
41
+ let(:actor) { mock }
42
+ let(:hostname) { '127.0.0.1' }
43
+ let(:port) { 9999 }
44
+ let(:path) { '/some_path' }
45
+ let(:custom_options) { { actor: actor, hostname: hostname, port: port, path: path } }
46
+
47
+ it 'parses options' do
48
+ @worker.parse_options(custom_options)
49
+ @worker.actor.should eq(actor)
50
+ @worker.hostname.should eq(hostname)
51
+ @worker.port.should eq(port)
52
+ @worker.path.should eq(path)
53
+ end
54
+
55
+ it 'sets defaults' do
56
+ @worker.parse_options({})
57
+ @worker.actor.should eq(nil)
58
+ @worker.hostname.should eq('0.0.0.0')
59
+ @worker.port.should eq(1234)
60
+ @worker.path.should eq('/ws')
61
+ end
62
+ end
63
+
64
+ describe '#debug_enabled?' do
65
+ it 'checks if debug is enabled' do
66
+ CelluloidPubsub::WebServer.expects(:debug_enabled?).returns(true)
67
+ act = @worker.debug_enabled?
68
+ act.should eq(true)
69
+ end
70
+ end
71
+
72
+ describe '#subscribe' do
73
+ let(:channel) { 'some_channel' }
74
+ it 'chats with the server' do
75
+ @worker.expects(:chat).with('client_action' => 'subscribe', 'channel' => channel)
76
+ @worker.subscribe(channel)
77
+ end
78
+ end
79
+
80
+ describe '#publish' do
81
+ let(:channel) { 'some_channel' }
82
+ let(:data) { 'some_message' }
83
+ it 'chats with the server' do
84
+ @worker.expects(:chat).with('client_action' => 'publish', 'channel' => channel, 'data' => data)
85
+ @worker.publish(channel, data)
86
+ end
87
+ end
88
+
89
+ describe '#on_open' do
90
+ let(:channel) { 'some_channel' }
91
+ let(:data) { 'some_message' }
92
+ it 'chats with the server' do
93
+ @worker.connect_blk.expects(:call)
94
+ @worker.on_open
95
+ end
96
+ end
97
+
98
+ describe '#on_message' do
99
+ let(:channel) { 'some_channel' }
100
+ let(:data) { 'some_message' }
101
+ it 'chats with the server' do
102
+ JSON.expects(:parse).with(data).returns(data)
103
+ @worker.actor.expects(:async).returns(actor)
104
+ @worker.actor.expects(:on_message).with(data)
105
+ @worker.on_message(data)
106
+ end
107
+ end
108
+
109
+ describe '#on_close' do
110
+ let(:channel) { 'some_channel' }
111
+ let(:code) { 'some_message' }
112
+ let(:reason) { 'some reason' }
113
+
114
+ it 'chats with the server' do
115
+ @worker.client.expects(:terminate)
116
+ @worker.actor.expects(:on_close).with(code, reason)
117
+ @worker.on_close(code, reason)
118
+ end
119
+ end
120
+
121
+ describe '#chat' do
122
+ let(:channel) { 'some_channel' }
123
+ let(:data) { 'some_message' }
124
+ let(:data_hash) { { a: 'some mesage ' } }
125
+ let(:json) { { action: 'message', message: data } }
126
+ it 'chats witout hash' do
127
+ JSON.expects(:dump).with(json).returns(json)
128
+ @worker.client.expects(:text).with(json)
129
+ @worker.send(:chat, data)
130
+ end
131
+
132
+ it 'chats with a hash' do
133
+ @worker.client.expects(:text).with(data_hash.to_json)
134
+ @worker.send(:chat, data_hash)
135
+ end
136
+ end
9
137
  end
@@ -3,4 +3,212 @@
3
3
  require 'spec_helper'
4
4
 
5
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
+ end
20
+
21
+ describe '#work' do
22
+ it 'works ' do
23
+ subject.expects(:run)
24
+ subject.work(websocket, server)
25
+ subject.websocket.should eq websocket
26
+ subject.server.should eq server
27
+ subject.channels.should eq []
28
+ end
29
+ end
30
+
31
+ # describe '#rub' do
32
+ # let(:data) { 'some message' }
33
+ #
34
+ # it 'works ' do
35
+ # subject.unstub(:run)
36
+ # websocket.stubs(:read).returns(data)
37
+ # subject.expects(:handle_websocket_message).with(data)
38
+ # subject.run
39
+ # end
40
+ # end
41
+
42
+ describe '#parse_json_data' do
43
+ let(:data) { 'some message' }
44
+ let(:expected) { data.to_json }
45
+
46
+ it 'works with hash ' do
47
+ JSON.expects(:parse).with(data).returns(expected)
48
+ actual = subject.parse_json_data(data)
49
+ actual.should eq expected
50
+ end
51
+
52
+ it 'works with exception parsing ' do
53
+ JSON.expects(:parse).with(data).raises(StandardError)
54
+ actual = subject.parse_json_data(data)
55
+ actual.should eq data
56
+ end
57
+ end
58
+
59
+ describe '#handle_websocket_message' do
60
+ let(:data) { 'some message' }
61
+ let(:json_data) { { a: 'b' } }
62
+
63
+ it 'handle_websocket_message' do
64
+ subject.expects(:parse_json_data).with(data).returns(json_data)
65
+ subject.expects(:handle_parsed_websocket_message).with(json_data)
66
+ subject.handle_websocket_message(data)
67
+ end
68
+ end
69
+
70
+ describe '#handle_parsed_websocket_message' do
71
+ it 'handle_websocket_message with a hash' do
72
+ data = { 'client_action' => 'b' }
73
+ data.expects(:stringify_keys).returns(data)
74
+ subject.expects(:delegate_action).with(data)
75
+ subject.handle_parsed_websocket_message(data)
76
+ end
77
+
78
+ it 'handle_websocket_message with something else than a hash' do
79
+ data = 'some message'
80
+ subject.expects(:handle_unknown_action).with(data)
81
+ subject.handle_parsed_websocket_message(data)
82
+ end
83
+ end
84
+
85
+ describe '#delegate_action' do
86
+ it 'unsubscribes all' do
87
+ data = { 'client_action' => 'unsubscribe_all' }
88
+ subject.expects(:unsubscribe_all).returns('bla')
89
+ subject.delegate_action(data)
90
+ end
91
+
92
+ it 'unsubscribes all' do
93
+ data = { 'client_action' => 'unsubscribe', 'channel' => 'some channel' }
94
+ subject.expects(:unsubscribe_client).with(data['channel'])
95
+ subject.delegate_action(data)
96
+ end
97
+
98
+ it 'subscribes to channell' do
99
+ data = { 'client_action' => 'subscribe', 'channel' => 'some channel' }
100
+ subject.expects(:start_subscriber).with(data['channel'], data)
101
+ subject.delegate_action(data)
102
+ end
103
+
104
+ it 'publish' do
105
+ data = { 'client_action' => 'publish', 'channel' => 'some channel', 'data' => 'some data' }
106
+ server.expects(:publish_event).with(data['channel'], data['data'].to_json)
107
+ subject.delegate_action(data)
108
+ end
109
+
110
+ it 'handles unknown' do
111
+ data = { 'client_action' => 'some action', 'channel' => 'some channel' }
112
+ subject.expects(:handle_unknown_action).with(data)
113
+ subject.delegate_action(data)
114
+ end
115
+ end
116
+
117
+ describe '#handle_unknown_action' do
118
+ it 'handles unknown' do
119
+ data = 'some data'
120
+ server.expects(:handle_dispatched_message)
121
+ subject.handle_unknown_action(data)
122
+ end
123
+ end
124
+
125
+ describe '#unsubscribe_client' do
126
+ let(:channel) { 'some channel' }
127
+ it 'returns nil' do
128
+ act = subject.unsubscribe_client('')
129
+ act.should eq(nil)
130
+ end
131
+
132
+ it 'unsubscribes' do
133
+ subject.channels.stubs(:blank?).returns(false)
134
+ subject.channels.expects(:delete).with(channel)
135
+ act = subject.unsubscribe_client(channel)
136
+ act.should eq(nil)
137
+ end
138
+
139
+ it 'unsubscribes' do
140
+ subject.channels.stubs(:blank?).returns(true)
141
+ subject.websocket.expects(:close)
142
+ act = subject.unsubscribe_client(channel)
143
+ act.should eq(nil)
144
+ end
145
+
146
+ it 'unsubscribes' do
147
+ subject.channels.stubs(:blank?).returns(false)
148
+ subject.channels.stubs(:delete)
149
+ server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
150
+ subject.unsubscribe_client(channel)
151
+ server.subscribers[channel].should eq([])
152
+ end
153
+ end
154
+
155
+ describe '#shutdown' do
156
+ it 'shutdowns' do
157
+ subject.expects(:terminate)
158
+ subject.shutdown
159
+ end
160
+ end
161
+
162
+ describe '#start_subscriber' do
163
+ let(:channel) { 'some channel' }
164
+ let(:message) { { a: 'b' } }
165
+
166
+ it 'subscribes ' do
167
+ act = subject.start_subscriber('', message)
168
+ act.should eq(nil)
169
+ end
170
+
171
+ it 'subscribes ' do
172
+ subject.stubs(:add_subscriber_to_channel).with(channel, message)
173
+ subject.websocket.expects(:<<).with(message.merge('client_action' => 'successful_subscription', 'channel' => channel).to_json)
174
+ subject.start_subscriber(channel, message)
175
+ end
176
+
177
+ # it 'raises error' do
178
+ # subject.stubs(:add_subscriber_to_channel).raises(StandardError)
179
+ #
180
+ # expect do
181
+ # subject.start_subscriber(channel, message)
182
+ # end.to raise_error(StandardError) { |e|
183
+ # expect(e.message).to include(channel)
184
+ # }
185
+ # end
186
+ end
187
+
188
+ describe '#add_subscriber_to_channel' do
189
+ let(:channel) { 'some channel' }
190
+ let(:message) { { a: 'b' } }
191
+
192
+ it 'adds subscribed' do
193
+ CelluloidPubsub::Registry.channels.stubs(:include?).with(channel).returns(false)
194
+ CelluloidPubsub::Registry.channels.expects(:<<).with(channel)
195
+ server.subscribers[channel] = []
196
+ server.subscribers[channel].expects(:<<).with(reactor: subject, message: message)
197
+ subject.add_subscriber_to_channel(channel, message)
198
+ subject.channels.should include(channel)
199
+ end
200
+ end
201
+
202
+ describe '#unsubscribe_all' do
203
+ let(:channel) { 'some channel' }
204
+ let(:message) { { a: 'b' } }
205
+
206
+ it 'adds subscribed' do
207
+ CelluloidPubsub::Registry.stubs(:channels).returns([channel])
208
+ server.subscribers.stubs(:[]).with(channel).returns([{ reactor: subject, message: message }])
209
+ subject.websocket.expects(:close)
210
+ subject.expects(:shutdown)
211
+ subject.unsubscribe_all
212
+ end
213
+ end
6
214
  end
@@ -3,4 +3,8 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe CelluloidPubsub::Registry do
6
+ it 'has class atributes' do
7
+ act = CelluloidPubsub::Registry.respond_to?(:channels)
8
+ act.should eq true
9
+ end
6
10
  end
@@ -3,4 +3,47 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe CelluloidPubsub::WebServer do
6
+ it 'should have host constant' do
7
+ CelluloidPubsub::WebServer::HOST.should eq('0.0.0.0')
8
+ end
9
+
10
+ it 'should have host constant' do
11
+ CelluloidPubsub::WebServer::PORT.should eq(1234)
12
+ end
13
+
14
+ it 'should have host constant' do
15
+ CelluloidPubsub::WebServer::PATH.should eq('/ws')
16
+ end
17
+ let(:options) { {} }
18
+ let(:web_server) { mock }
19
+
20
+ before(:each) do
21
+ CelluloidPubsub::WebServer.stubs(:new).returns(web_server)
22
+ end
23
+
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
6
49
  end
data/spec/spec_helper.rb CHANGED
@@ -46,3 +46,11 @@ RSpec.configure do |config|
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ # class used for testing actions
51
+ class TestActor
52
+ include Celluloid
53
+ include Celluloid::Logger
54
+ end
55
+
56
+ TestActor.supervise_as(:test_actor)