ably-rest 0.8.15 → 0.9.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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/lib/submodules/ably-ruby/CHANGELOG.md +61 -48
  3. data/lib/submodules/ably-ruby/README.md +0 -6
  4. data/lib/submodules/ably-ruby/ably.gemspec +1 -1
  5. data/lib/submodules/ably-ruby/lib/ably/auth.rb +37 -32
  6. data/lib/submodules/ably-ruby/lib/ably/modules/event_emitter.rb +15 -30
  7. data/lib/submodules/ably-ruby/lib/ably/modules/model_common.rb +0 -25
  8. data/lib/submodules/ably-ruby/lib/ably/realtime/auth.rb +30 -18
  9. data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb +3 -3
  10. data/lib/submodules/ably-ruby/lib/ably/realtime/client.rb +0 -3
  11. data/lib/submodules/ably-ruby/lib/ably/realtime/client/incoming_message_dispatcher.rb +2 -2
  12. data/lib/submodules/ably-ruby/lib/ably/realtime/connection/connection_manager.rb +3 -3
  13. data/lib/submodules/ably-ruby/lib/ably/realtime/presence/members_map.rb +3 -3
  14. data/lib/submodules/ably-ruby/lib/ably/rest/client.rb +6 -6
  15. data/lib/submodules/ably-ruby/lib/ably/version.rb +2 -2
  16. data/lib/submodules/ably-ruby/spec/acceptance/realtime/auth_spec.rb +66 -53
  17. data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb +8 -10
  18. data/lib/submodules/ably-ruby/spec/acceptance/realtime/client_spec.rb +3 -3
  19. data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_spec.rb +12 -48
  20. data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb +38 -79
  21. data/lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb +74 -40
  22. data/lib/submodules/ably-ruby/spec/acceptance/rest/base_spec.rb +1 -1
  23. data/lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb +4 -2
  24. data/lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb +21 -26
  25. data/lib/submodules/ably-ruby/spec/acceptance/rest/presence_spec.rb +12 -10
  26. data/lib/submodules/ably-ruby/spec/unit/modules/event_emitter_spec.rb +51 -109
  27. data/lib/submodules/ably-ruby/spec/unit/realtime/presence_spec.rb +3 -3
  28. metadata +4 -3
@@ -137,7 +137,7 @@ describe Ably::Rest do
137
137
 
138
138
  context 'when auth#token_renewable?' do
139
139
  before do
140
- client.auth.authorise
140
+ client.auth.authorize
141
141
  end
142
142
 
143
143
  it 'should automatically reissue a token' do
@@ -360,7 +360,10 @@ describe Ably::Rest::Channel do
360
360
  let(:channel_name) { "persisted:#{random_str(4)}" }
361
361
  let(:channel) { client.channel(channel_name) }
362
362
  let(:endpoint) do
363
- client.endpoint
363
+ client.endpoint.tap do |client_end_point|
364
+ client_end_point.user = key_name
365
+ client_end_point.password = key_secret
366
+ end
364
367
  end
365
368
  let(:default_history_options) do
366
369
  {
@@ -375,7 +378,6 @@ describe Ably::Rest::Channel do
375
378
  query_params = default_history_options
376
379
  .merge(option => milliseconds).map { |k, v| "#{k}=#{v}" }.join('&')
377
380
  stub_request(:get, "#{endpoint}/channels/#{Addressable::URI.encode(channel_name)}/messages?#{query_params}").
378
- with(basic_auth: [key_name, key_secret]).
379
381
  to_return(:body => '{}', :headers => { 'Content-Type' => 'application/json' })
380
382
  }
381
383
 
@@ -111,8 +111,7 @@ describe Ably::Rest::Client do
111
111
  let(:client_options) { default_options.merge(key: api_key) }
112
112
 
113
113
  let!(:get_message_history_stub) do
114
- stub_request(:get, "https://#{environment}-#{Ably::Rest::Client::DOMAIN}/channels/#{channel_name}/messages?#{history_querystring}").
115
- with(basic_auth: [key_name, key_secret]).
114
+ stub_request(:get, "https://#{api_key}@#{environment}-#{Ably::Rest::Client::DOMAIN}/channels/#{channel_name}/messages?#{history_querystring}").
116
115
  to_return(body: [], headers: { 'Content-Type' => 'application/json' })
117
116
  end
118
117
 
@@ -285,9 +284,7 @@ describe Ably::Rest::Client do
285
284
  context 'when environment is NOT production' do
286
285
  let(:client_options) { default_options.merge(environment: 'sandbox', key: api_key) }
287
286
  let!(:default_host_request_stub) do
288
- stub_request(:post, "https://#{environment}-#{Ably::Rest::Client::DOMAIN}#{path}").
289
- with(basic_auth: [key_name, key_secret]).
290
- to_return do
287
+ stub_request(:post, "https://#{api_key}@#{environment}-#{Ably::Rest::Client::DOMAIN}#{path}").to_return do
291
288
  raise Faraday::TimeoutError.new('timeout error message')
292
289
  end
293
290
  end
@@ -316,16 +313,16 @@ describe Ably::Rest::Client do
316
313
  end
317
314
 
318
315
  let!(:first_fallback_request_stub) do
319
- stub_request(:post, "https://#{custom_hosts[0]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
316
+ stub_request(:post, "https://#{api_key}@#{custom_hosts[0]}#{path}").to_return(&fallback_block)
320
317
  end
321
318
 
322
319
  let!(:second_fallback_request_stub) do
323
- stub_request(:post, "https://#{custom_hosts[1]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
320
+ stub_request(:post, "https://#{api_key}@#{custom_hosts[1]}#{path}").to_return(&fallback_block)
324
321
  end
325
322
 
326
323
  context 'and connection times out' do
327
324
  let!(:default_host_request_stub) do
328
- stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return do
325
+ stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return do
329
326
  raise Faraday::TimeoutError.new('timeout error message')
330
327
  end
331
328
  end
@@ -339,7 +336,7 @@ describe Ably::Rest::Client do
339
336
 
340
337
  context "and the total request time exeeds #{http_defaults.fetch(:max_retry_duration)} seconds" do
341
338
  let!(:default_host_request_stub) do
342
- stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return do
339
+ stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return do
343
340
  sleep max_retry_duration * 1.5
344
341
  raise Faraday::TimeoutError.new('timeout error message')
345
342
  end
@@ -356,7 +353,7 @@ describe Ably::Rest::Client do
356
353
 
357
354
  context 'and connection fails' do
358
355
  let!(:default_host_request_stub) do
359
- stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return do
356
+ stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return do
360
357
  raise Faraday::ConnectionFailed.new('connection failure error message')
361
358
  end
362
359
  end
@@ -372,7 +369,7 @@ describe Ably::Rest::Client do
372
369
  context 'and basic authentication fails' do
373
370
  let(:status) { 401 }
374
371
  let!(:default_host_request_stub) do
375
- stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return(
372
+ stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return(
376
373
  headers: { 'Content-Type' => 'application/json' },
377
374
  status: status,
378
375
  body: {
@@ -404,7 +401,7 @@ describe Ably::Rest::Client do
404
401
  end
405
402
  end
406
403
  let!(:default_host_request_stub) do
407
- stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
404
+ stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return(&fallback_block)
408
405
  end
409
406
 
410
407
  it 'attempts the fallback hosts as this is an authentication failure' do
@@ -440,20 +437,20 @@ describe Ably::Rest::Client do
440
437
  end
441
438
  end
442
439
  let!(:default_host_request_stub) do
443
- stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
440
+ stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return(&fallback_block)
444
441
  end
445
442
 
446
443
  context 'with custom fallback hosts provided' do
447
444
  let!(:first_fallback_request_stub) do
448
- stub_request(:post, "https://#{custom_hosts[0]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
445
+ stub_request(:post, "https://#{api_key}@#{custom_hosts[0]}#{path}").to_return(&fallback_block)
449
446
  end
450
447
 
451
448
  let!(:second_fallback_request_stub) do
452
- stub_request(:post, "https://#{custom_hosts[1]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
449
+ stub_request(:post, "https://#{api_key}@#{custom_hosts[1]}#{path}").to_return(&fallback_block)
453
450
  end
454
451
 
455
452
  let(:client_options) {
456
- production_options.merge(fallback_hosts: custom_hosts, log_level: :error)
453
+ production_options.merge(fallback_hosts: custom_hosts)
457
454
  }
458
455
 
459
456
  it 'attempts the fallback hosts as this is an authentication failure (#RSC15b, #TO3k6)' do
@@ -519,8 +516,7 @@ describe Ably::Rest::Client do
519
516
  port: port,
520
517
  tls: false,
521
518
  http_request_timeout: request_timeout,
522
- max_retry_duration: request_timeout * 3,
523
- log_level: :error
519
+ max_retry_duration: request_timeout * 3
524
520
  )
525
521
  end
526
522
  let(:fail_fallback_request_count) { 1 }
@@ -623,16 +619,16 @@ describe Ably::Rest::Client do
623
619
  end
624
620
  end
625
621
  let!(:default_host_request_stub) do
626
- stub_request(:post, "https://#{env}-#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
622
+ stub_request(:post, "https://#{api_key}@#{env}-#{Ably::Rest::Client::DOMAIN}#{path}").to_return(&fallback_block)
627
623
  end
628
624
 
629
625
  context 'with custom fallback hosts provided (#RSC15b, #TO3k6)' do
630
626
  let!(:first_fallback_request_stub) do
631
- stub_request(:post, "https://#{custom_hosts[0]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
627
+ stub_request(:post, "https://#{api_key}@#{custom_hosts[0]}#{path}").to_return(&fallback_block)
632
628
  end
633
629
 
634
630
  let!(:second_fallback_request_stub) do
635
- stub_request(:post, "https://#{custom_hosts[1]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
631
+ stub_request(:post, "https://#{api_key}@#{custom_hosts[1]}#{path}").to_return(&fallback_block)
636
632
  end
637
633
 
638
634
  let(:client_options) {
@@ -670,11 +666,11 @@ describe Ably::Rest::Client do
670
666
  }
671
667
 
672
668
  let!(:first_fallback_request_stub) do
673
- stub_request(:post, "https://#{Ably::FALLBACK_HOSTS[0]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
669
+ stub_request(:post, "https://#{api_key}@#{Ably::FALLBACK_HOSTS[0]}#{path}").to_return(&fallback_block)
674
670
  end
675
671
 
676
672
  let!(:second_fallback_request_stub) do
677
- stub_request(:post, "https://#{Ably::FALLBACK_HOSTS[1]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block)
673
+ stub_request(:post, "https://#{api_key}@#{Ably::FALLBACK_HOSTS[1]}#{path}").to_return(&fallback_block)
678
674
  end
679
675
 
680
676
  let(:client_options) {
@@ -705,7 +701,7 @@ describe Ably::Rest::Client do
705
701
  let(:path) { '/channels/test/publish' }
706
702
 
707
703
  let!(:custom_host_request_stub) do
708
- stub_request(:post, "https://#{custom_host}#{path}").with(basic_auth: [key_name, key_secret]).to_return do
704
+ stub_request(:post, "https://#{api_key}@#{custom_host}#{path}").to_return do
709
705
  raise Faraday::ConnectionFailed.new('connection failure error message')
710
706
  end
711
707
  end
@@ -844,12 +840,11 @@ describe Ably::Rest::Client do
844
840
  lib << Ably::VERSION
845
841
 
846
842
 
847
- stub_request(:post, "#{client.endpoint.to_s.gsub('://', "://")}/channels/foo/publish").
843
+ stub_request(:post, "#{client.endpoint.to_s.gsub('://', "://#{api_key}@")}/channels/foo/publish").
848
844
  with(headers: {
849
845
  'X-Ably-Version' => Ably::PROTOCOL_VERSION,
850
846
  'X-Ably-Lib' => lib.join('-')
851
847
  }).
852
- with(basic_auth: [key_name, key_secret]).
853
848
  to_return(status: 201, body: '{}', headers: { 'Content-Type' => 'application/json' })
854
849
  end
855
850
 
@@ -69,12 +69,14 @@ describe Ably::Rest::Presence do
69
69
  }
70
70
  end
71
71
  let(:endpoint) do
72
- client.endpoint
72
+ client.endpoint.tap do |client_end_point|
73
+ client_end_point.user = key_name
74
+ client_end_point.password = key_secret
75
+ end
73
76
  end
74
77
  let!(:get_stub) {
75
78
  query_params = query_options.map { |k, v| "#{k}=#{v}" }.join('&')
76
79
  stub_request(:get, "#{endpoint}/channels/#{Addressable::URI.encode(channel_name)}/presence?#{query_params}").
77
- with(basic_auth: [key_name, key_secret]).
78
80
  to_return(:body => '{}', :headers => { 'Content-Type' => 'application/json' })
79
81
  }
80
82
  let(:channel_name) { random_str }
@@ -180,7 +182,10 @@ describe Ably::Rest::Presence do
180
182
  let(:user) { 'appid.keyuid' }
181
183
  let(:secret) { random_str(8) }
182
184
  let(:endpoint) do
183
- client.endpoint
185
+ client.endpoint.tap do |client_end_point|
186
+ client_end_point.user = user
187
+ client_end_point.password = secret
188
+ end
184
189
  end
185
190
  let(:client) do
186
191
  Ably::Rest::Client.new(key: "#{user}:#{secret}")
@@ -196,7 +201,6 @@ describe Ably::Rest::Presence do
196
201
  let!(:history_stub) {
197
202
  query_params = history_options.map { |k, v| "#{k}=#{v}" }.join('&')
198
203
  stub_request(:get, "#{endpoint}/channels/#{Addressable::URI.encode(channel_name)}/presence/history?#{query_params}").
199
- with(basic_auth: [user, secret]).
200
204
  to_return(:body => '{}', :headers => { 'Content-Type' => 'application/json' })
201
205
  }
202
206
 
@@ -237,7 +241,6 @@ describe Ably::Rest::Presence do
237
241
  let!(:history_stub) {
238
242
  query_params = history_options.map { |k, v| "#{k}=#{v}" }.join('&')
239
243
  stub_request(:get, "#{endpoint}/channels/#{Addressable::URI.encode(channel_name)}/presence/history?#{query_params}").
240
- with(basic_auth: [user, secret]).
241
244
  to_return(:body => '{}', :headers => { 'Content-Type' => 'application/json' })
242
245
  }
243
246
 
@@ -307,7 +310,10 @@ describe Ably::Rest::Presence do
307
310
  let(:user) { 'appid.keyuid' }
308
311
  let(:secret) { random_str(8) }
309
312
  let(:endpoint) do
310
- client.endpoint
313
+ client.endpoint.tap do |client_end_point|
314
+ client_end_point.user = user
315
+ client_end_point.password = secret
316
+ end
311
317
  end
312
318
  let(:client) do
313
319
  Ably::Rest::Client.new(client_options.merge(key: "#{user}:#{secret}"))
@@ -342,7 +348,6 @@ describe Ably::Rest::Presence do
342
348
  context '#get' do
343
349
  let!(:get_stub) {
344
350
  stub_request(:get, "#{endpoint}/channels/#{Addressable::URI.encode(channel_name)}/presence?limit=100").
345
- with(basic_auth: [user, secret]).
346
351
  to_return(:body => serialized_encoded_message, :headers => { 'Content-Type' => content_type })
347
352
  }
348
353
 
@@ -360,7 +365,6 @@ describe Ably::Rest::Presence do
360
365
  context '#history' do
361
366
  let!(:history_stub) {
362
367
  stub_request(:get, "#{endpoint}/channels/#{Addressable::URI.encode(channel_name)}/presence/history?direction=backwards&limit=100").
363
- with(basic_auth: [user, secret]).
364
368
  to_return(:body => serialized_encoded_message, :headers => { 'Content-Type' => content_type })
365
369
  }
366
370
 
@@ -391,7 +395,6 @@ describe Ably::Rest::Presence do
391
395
  let(:client_options) { default_options.merge(log_level: :fatal) }
392
396
  let!(:get_stub) {
393
397
  stub_request(:get, "#{endpoint}/channels/#{Addressable::URI.encode(channel_name)}/presence?limit=100").
394
- with(basic_auth: [user, secret]).
395
398
  to_return(:body => serialized_encoded_message_with_invalid_encoding, :headers => { 'Content-Type' => content_type })
396
399
  }
397
400
  let(:presence_message) { presence.get.items.first }
@@ -416,7 +419,6 @@ describe Ably::Rest::Presence do
416
419
  let(:client_options) { default_options.merge(log_level: :fatal) }
417
420
  let!(:history_stub) {
418
421
  stub_request(:get, "#{endpoint}/channels/#{Addressable::URI.encode(channel_name)}/presence/history?direction=backwards&limit=100").
419
- with(basic_auth: [user, secret]).
420
422
  to_return(:body => serialized_encoded_message_with_invalid_encoding, :headers => { 'Content-Type' => content_type })
421
423
  }
422
424
  let(:presence_message) { presence.history.items.first }
@@ -128,34 +128,17 @@ describe Ably::Modules::EventEmitter do
128
128
  end
129
129
 
130
130
  context '#on' do
131
- context 'with event specified' do
132
- it 'calls the block every time an event is emitted only' do
133
- block_called = 0
134
- subject.on('event') { block_called += 1 }
135
- 3.times { subject.emit 'event', 'data' }
136
- expect(block_called).to eql(3)
137
- end
138
-
139
- it 'catches exceptions in the provided block, logs the error and continues' do
140
- expect(subject.logger).to receive(:error).with(/Intentional exception/)
141
- subject.on(:event) { raise 'Intentional exception' }
142
- subject.emit :event
143
- end
131
+ it 'calls the block every time an event is emitted only' do
132
+ block_called = 0
133
+ subject.on('event') { block_called += 1 }
134
+ 3.times { subject.emit 'event', 'data' }
135
+ expect(block_called).to eql(3)
144
136
  end
145
137
 
146
- context 'with no event specified' do
147
- it 'calls the block every time an event is emitted only' do
148
- block_called = 0
149
- subject.on { block_called += 1 }
150
- 3.times { subject.emit 'event', 'data' }
151
- expect(block_called).to eql(3)
152
- end
153
-
154
- it 'catches exceptions in the provided block, logs the error and continues' do
155
- expect(subject.logger).to receive(:error).with(/Intentional exception/)
156
- subject.on { raise 'Intentional exception' }
157
- subject.emit :event
158
- end
138
+ it 'catches exceptions in the provided block, logs the error and continues' do
139
+ expect(subject.logger).to receive(:error).with(/Intentional exception/)
140
+ subject.on(:event) { raise 'Intentional exception' }
141
+ subject.emit :event
159
142
  end
160
143
  end
161
144
 
@@ -174,50 +157,25 @@ describe Ably::Modules::EventEmitter do
174
157
  end
175
158
 
176
159
  context '#once' do
177
- context 'with event specified' do
178
- it 'calls the block the first time an event is emitted only' do
179
- block_called = 0
180
- subject.once('event') { block_called += 1 }
181
- 3.times { subject.emit 'event', 'data' }
182
- expect(block_called).to eql(1)
183
- end
184
-
185
- it 'does not remove other blocks after it is called' do
186
- block_called = 0
187
- subject.once('event') { block_called += 1 }
188
- subject.on('event') { block_called += 1 }
189
- 3.times { subject.emit 'event', 'data' }
190
- expect(block_called).to eql(4)
191
- end
192
-
193
- it 'catches exceptions in the provided block, logs the error and continues' do
194
- expect(subject.logger).to receive(:error).with(/Intentional exception/)
195
- subject.once(:event) { raise 'Intentional exception' }
196
- subject.emit :event
197
- end
160
+ it 'calls the block the first time an event is emitted only' do
161
+ block_called = 0
162
+ subject.once('event') { block_called += 1 }
163
+ 3.times { subject.emit 'event', 'data' }
164
+ expect(block_called).to eql(1)
198
165
  end
199
166
 
200
- context 'with no event specified' do
201
- it 'calls the block the first time an event is emitted only' do
202
- block_called = 0
203
- subject.once { block_called += 1 }
204
- 3.times { subject.emit 'event', 'data' }
205
- expect(block_called).to eql(1)
206
- end
207
-
208
- it 'does not remove other blocks after it is called' do
209
- block_called = 0
210
- subject.once { block_called += 1 }
211
- subject.on { block_called += 1 }
212
- 3.times { subject.emit 'event', 'data' }
213
- expect(block_called).to eql(4)
214
- end
167
+ it 'does not remove other blocks after it is called' do
168
+ block_called = 0
169
+ subject.once('event') { block_called += 1 }
170
+ subject.on('event') { block_called += 1 }
171
+ 3.times { subject.emit 'event', 'data' }
172
+ expect(block_called).to eql(4)
173
+ end
215
174
 
216
- it 'catches exceptions in the provided block, logs the error and continues' do
217
- expect(subject.logger).to receive(:error).with(/Intentional exception/)
218
- subject.once { raise 'Intentional exception' }
219
- subject.emit :event
220
- end
175
+ it 'catches exceptions in the provided block, logs the error and continues' do
176
+ expect(subject.logger).to receive(:error).with(/Intentional exception/)
177
+ subject.once(:event) { raise 'Intentional exception' }
178
+ subject.emit :event
221
179
  end
222
180
  end
223
181
 
@@ -238,57 +196,41 @@ describe Ably::Modules::EventEmitter do
238
196
  context '#off' do
239
197
  let(:callback) { Proc.new { |msg| obj.received_message msg } }
240
198
 
241
- context 'with event specified in on handler' do
242
- before do
243
- subject.on(:message, &callback)
244
- end
245
-
246
- after do
247
- subject.emit :message, msg
248
- end
249
-
250
- context 'with event names as arguments' do
251
- it 'deletes matching callbacks' do
252
- expect(obj).to_not receive(:received_message).with(msg)
253
- subject.off(:message, &callback)
254
- end
199
+ before do
200
+ subject.on(:message, &callback)
201
+ end
255
202
 
256
- it 'deletes all callbacks if not block given' do
257
- expect(obj).to_not receive(:received_message).with(msg)
258
- subject.off(:message)
259
- end
203
+ after do
204
+ subject.emit :message, msg
205
+ end
260
206
 
261
- it 'continues if the block does not exist' do
262
- expect(obj).to receive(:received_message).with(msg)
263
- subject.off(:message) { true }
264
- end
207
+ context 'with event names as arguments' do
208
+ it 'deletes matching callbacks' do
209
+ expect(obj).to_not receive(:received_message).with(msg)
210
+ subject.off(:message, &callback)
265
211
  end
266
212
 
267
- context 'without any event names' do
268
- it 'deletes all matching callbacks' do
269
- expect(obj).to_not receive(:received_message).with(msg)
270
- subject.off(&callback)
271
- end
213
+ it 'deletes all callbacks if not block given' do
214
+ expect(obj).to_not receive(:received_message).with(msg)
215
+ subject.off(:message)
216
+ end
272
217
 
273
- it 'deletes all callbacks if not block given' do
274
- expect(obj).to_not receive(:received_message).with(msg)
275
- subject.off
276
- end
218
+ it 'continues if the block does not exist' do
219
+ expect(obj).to receive(:received_message).with(msg)
220
+ subject.off(:message) { true }
277
221
  end
278
222
  end
279
223
 
280
- it 'removes handler added with no event specified' do
281
- subject.on(&callback)
282
- expect(obj).to_not receive(:received_message).with(msg)
283
- subject.off(&callback)
284
- subject.emit :message, msg
285
- end
224
+ context 'without any event names' do
225
+ it 'deletes all matching callbacks' do
226
+ expect(obj).to_not receive(:received_message).with(msg)
227
+ subject.off(&callback)
228
+ end
286
229
 
287
- it 'leaves handler when event specified' do
288
- subject.on(&callback)
289
- expect(obj).to receive(:received_message).with(msg)
290
- subject.off(:foo, &callback)
291
- subject.emit :message, msg
230
+ it 'deletes all callbacks if not block given' do
231
+ expect(obj).to_not receive(:received_message).with(msg)
232
+ subject.off
233
+ end
292
234
  end
293
235
  end
294
236
  end