blather 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +7 -7
- data/CHANGELOG.md +8 -0
- data/blather.gemspec +6 -6
- data/lib/blather.rb +1 -1
- data/lib/blather/client/client.rb +30 -6
- data/lib/blather/version.rb +1 -1
- data/spec/blather/client/client_spec.rb +73 -68
- data/spec/blather/client/dsl/pubsub_spec.rb +121 -121
- data/spec/blather/client/dsl_spec.rb +9 -9
- data/spec/blather/errors/sasl_error_spec.rb +3 -3
- data/spec/blather/errors/stanza_error_spec.rb +26 -26
- data/spec/blather/errors/stream_error_spec.rb +22 -22
- data/spec/blather/errors_spec.rb +7 -7
- data/spec/blather/file_transfer_spec.rb +9 -9
- data/spec/blather/jid_spec.rb +29 -29
- data/spec/blather/roster_item_spec.rb +18 -18
- data/spec/blather/roster_spec.rb +18 -18
- data/spec/blather/stanza/discos/disco_info_spec.rb +56 -56
- data/spec/blather/stanza/discos/disco_items_spec.rb +33 -33
- data/spec/blather/stanza/iq/command_spec.rb +51 -51
- data/spec/blather/stanza/iq/ibb_spec.rb +15 -15
- data/spec/blather/stanza/iq/ping_spec.rb +8 -8
- data/spec/blather/stanza/iq/query_spec.rb +15 -15
- data/spec/blather/stanza/iq/roster_spec.rb +29 -29
- data/spec/blather/stanza/iq/s5b_spec.rb +7 -7
- data/spec/blather/stanza/iq/si_spec.rb +17 -17
- data/spec/blather/stanza/iq/vcard_spec.rb +19 -19
- data/spec/blather/stanza/iq_spec.rb +11 -11
- data/spec/blather/stanza/message/muc_user_spec.rb +32 -32
- data/spec/blather/stanza/message_spec.rb +53 -54
- data/spec/blather/stanza/presence/c_spec.rb +11 -11
- data/spec/blather/stanza/presence/muc_spec.rb +7 -7
- data/spec/blather/stanza/presence/muc_user_spec.rb +22 -22
- data/spec/blather/stanza/presence/status_spec.rb +33 -33
- data/spec/blather/stanza/presence/subscription_spec.rb +22 -22
- data/spec/blather/stanza/presence_spec.rb +30 -30
- data/spec/blather/stanza/pubsub/affiliations_spec.rb +11 -11
- data/spec/blather/stanza/pubsub/create_spec.rb +10 -10
- data/spec/blather/stanza/pubsub/event_spec.rb +24 -24
- data/spec/blather/stanza/pubsub/items_spec.rb +20 -20
- data/spec/blather/stanza/pubsub/publish_spec.rb +21 -21
- data/spec/blather/stanza/pubsub/retract_spec.rb +19 -19
- data/spec/blather/stanza/pubsub/subscribe_spec.rb +17 -17
- data/spec/blather/stanza/pubsub/subscription_spec.rb +28 -28
- data/spec/blather/stanza/pubsub/subscriptions_spec.rb +13 -13
- data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +22 -22
- data/spec/blather/stanza/pubsub_owner/delete_spec.rb +9 -9
- data/spec/blather/stanza/pubsub_owner/purge_spec.rb +9 -9
- data/spec/blather/stanza/pubsub_owner_spec.rb +6 -6
- data/spec/blather/stanza/pubsub_spec.rb +15 -15
- data/spec/blather/stanza/x_spec.rb +53 -53
- data/spec/blather/stanza_spec.rb +39 -39
- data/spec/blather/stream/client_spec.rb +160 -160
- data/spec/blather/stream/component_spec.rb +8 -10
- data/spec/blather/stream/parser_spec.rb +25 -25
- data/spec/blather/stream/ssl_spec.rb +3 -3
- data/spec/blather/xmpp_node_spec.rb +9 -9
- data/spec/blather_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +26 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aeaa80653766a8a8a6fd2054b2e3265306f9e7182ca5bfbbb9df66f9d7ce6f0f
|
4
|
+
data.tar.gz: 8998041476db54c0fb00efec13ddbee3403fcf35d9099318c352db104a5d8837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69b1624e91b0f2cd1d43c9d5de90eaec038b04191a370113d02547ee6c68ba1b00b981371756184550cf72a9242479c9b7d2ebb8c94c856ea23d654cc5b2f5b3
|
7
|
+
data.tar.gz: b21b1651df0b249d6f8fbc970e86e186b5fce044e90060ebed46fed1d93c9c3e11550c8cc2961b074ca37a0a0a8157820bd18b8e9df37a5b4164221d8d1ac268
|
data/.travis.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
-
-
|
6
|
-
-
|
7
|
-
- rbx-2.1.1
|
3
|
+
- 2.3.7
|
4
|
+
- 2.4.4
|
5
|
+
- jruby-9.1.17.0
|
6
|
+
- rbx-3.105
|
8
7
|
- ruby-head
|
8
|
+
jdk:
|
9
|
+
- openjdk8 # for jruby
|
9
10
|
matrix:
|
10
11
|
allow_failures:
|
11
|
-
- rvm: jruby
|
12
12
|
- rvm: ruby-head
|
13
|
-
- rvm: rbx-
|
13
|
+
- rvm: rbx-3.105
|
14
14
|
before_install:
|
15
15
|
- gem install bundler
|
16
16
|
notifications:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# [develop](https://github.com/adhearsion/blather/compare/master...develop)
|
2
2
|
|
3
|
+
# [v2.0.0](https://github.com/adhearsion/blather/compare/v1.2.0...v2.0.0) - [2018-06-18](https://rubygems.org/gems/blather/versions/2.0.0)
|
4
|
+
* Bugfix: Require EventMachine >= 1.2.6 to avoid segfault issue
|
5
|
+
* Bugfix: Fix unsafe threaded use of @tmp_handlers in Blather::Client
|
6
|
+
* Feature: Bump RSpec to 3.x and convert specs with Transpec
|
7
|
+
* Feature: Bump Mocha version to 1.x
|
8
|
+
* Feature: Switch from girl_friday to sucker_punch
|
9
|
+
* Feature: Unlock Nokogiri to allow >=1.8.3 now that issues are fixed upstream
|
10
|
+
|
3
11
|
# [v1.2.0](https://github.com/adhearsion/blather/compare/v1.1.4...v1.2.0) - [2016-01-07](https://rubygems.org/gems/blather/versions/1.2.0)
|
4
12
|
* Bugfix: Properly sort resources with the same priority but different status
|
5
13
|
* Bugfix: Lock to Nokogiri <= 1.6.1 because new versions are more broken than old ones
|
data/blather.gemspec
CHANGED
@@ -34,18 +34,18 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.rdoc_options = %w{--charset=UTF-8}
|
35
35
|
s.extra_rdoc_files = %w{LICENSE README.md}
|
36
36
|
|
37
|
-
s.add_dependency "eventmachine", [">= 1.
|
38
|
-
s.add_dependency "nokogiri", ["~> 1.
|
37
|
+
s.add_dependency "eventmachine", ["~> 1.2", ">= 1.2.6"]
|
38
|
+
s.add_dependency "nokogiri", ["~> 1.8", ">= 1.8.3"]
|
39
39
|
s.add_dependency "niceogiri", ["~> 1.0"]
|
40
40
|
s.add_dependency "activesupport", [">= 2.3.11"]
|
41
|
-
s.add_dependency "
|
41
|
+
s.add_dependency "sucker_punch", ["~> 2.0"]
|
42
42
|
|
43
43
|
s.add_development_dependency "bundler", ["~> 1.0"]
|
44
44
|
s.add_development_dependency "rake"
|
45
|
-
s.add_development_dependency "rspec", ["~>
|
46
|
-
s.add_development_dependency "mocha", ["~> 0
|
45
|
+
s.add_development_dependency "rspec", ["~> 3.0"]
|
46
|
+
s.add_development_dependency "mocha", ["~> 1.0"]
|
47
47
|
s.add_development_dependency "guard-rspec"
|
48
|
-
s.add_development_dependency "yard", ["~> 0.
|
48
|
+
s.add_development_dependency "yard", ["~> 0.9.11"]
|
49
49
|
s.add_development_dependency "bluecloth" unless jruby? || rbx?
|
50
50
|
s.add_development_dependency "countdownlatch"
|
51
51
|
s.add_development_dependency 'rb-fsevent', ['~> 0.9']
|
data/lib/blather.rb
CHANGED
@@ -32,6 +32,21 @@ module Blather
|
|
32
32
|
# end
|
33
33
|
#
|
34
34
|
class Client
|
35
|
+
class Job
|
36
|
+
include SuckerPunch::Job
|
37
|
+
class_attribute :client
|
38
|
+
|
39
|
+
def perform(stanza)
|
40
|
+
client.handle_data stanza
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.shutdown
|
44
|
+
SuckerPunch::Queue.all.each do |queue|
|
45
|
+
queue.shutdown if queue.name == to_s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
35
50
|
attr_reader :jid,
|
36
51
|
:roster,
|
37
52
|
:caps,
|
@@ -62,6 +77,7 @@ module Blather
|
|
62
77
|
@status = Stanza::Presence::Status.new
|
63
78
|
@handlers = {}
|
64
79
|
@tmp_handlers = {}
|
80
|
+
@tmp_handlers_mutex = Mutex.new
|
65
81
|
@filters = {:before => [], :after => []}
|
66
82
|
@roster = Roster.new self
|
67
83
|
@caps = Stanza::Capabilities.new
|
@@ -124,7 +140,9 @@ module Blather
|
|
124
140
|
# @param [#to_s] id the ID of the stanza that should be handled
|
125
141
|
# @yield [Blather::Stanza] stanza the incomming stanza
|
126
142
|
def register_tmp_handler(id, &handler)
|
127
|
-
@
|
143
|
+
@tmp_handlers_mutex.synchronize do
|
144
|
+
@tmp_handlers[id.to_s] = handler
|
145
|
+
end
|
128
146
|
end
|
129
147
|
|
130
148
|
# Clear handlers with given guards
|
@@ -194,7 +212,7 @@ module Blather
|
|
194
212
|
# @private
|
195
213
|
def receive_data(stanza)
|
196
214
|
if handler_queue
|
197
|
-
handler_queue
|
215
|
+
handler_queue.perform_async stanza
|
198
216
|
else
|
199
217
|
handle_data stanza
|
200
218
|
end
|
@@ -229,9 +247,11 @@ module Blather
|
|
229
247
|
# @private
|
230
248
|
def handler_queue
|
231
249
|
return if queue_size == 0
|
232
|
-
@handler_queue
|
233
|
-
|
234
|
-
|
250
|
+
return @handler_queue if @handler_queue
|
251
|
+
@handler_queue = Class.new(Job)
|
252
|
+
@handler_queue.client = self
|
253
|
+
@handler_queue.workers queue_size
|
254
|
+
return @handler_queue
|
235
255
|
end
|
236
256
|
|
237
257
|
protected
|
@@ -293,7 +313,11 @@ module Blather
|
|
293
313
|
end
|
294
314
|
|
295
315
|
def handle_stanza(stanza)
|
296
|
-
|
316
|
+
handler = @tmp_handlers_mutex.synchronize do
|
317
|
+
@tmp_handlers.delete(stanza.id)
|
318
|
+
end
|
319
|
+
|
320
|
+
if handler
|
297
321
|
handler.call stanza
|
298
322
|
else
|
299
323
|
stanza.handler_hierarchy.each do |type|
|
data/lib/blather/version.rb
CHANGED
@@ -11,42 +11,42 @@ describe Blather::Client do
|
|
11
11
|
|
12
12
|
it 'provides a Blather::JID reader' do
|
13
13
|
subject.post_init stream, jid
|
14
|
-
subject.
|
15
|
-
subject.jid.
|
14
|
+
expect(subject).to respond_to :jid
|
15
|
+
expect(subject.jid).to eq(jid)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'provides a reader for the roster' do
|
19
|
-
subject.
|
20
|
-
subject.roster.
|
19
|
+
expect(subject).to respond_to :roster
|
20
|
+
expect(subject.roster).to be_kind_of Blather::Roster
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'provides a status reader' do
|
24
24
|
subject.post_init stream, jid
|
25
|
-
subject.
|
25
|
+
expect(subject).to respond_to :status
|
26
26
|
subject.status = :away
|
27
|
-
subject.status.
|
27
|
+
expect(subject.status).to eq(:away)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should have a caps handler' do
|
31
|
-
subject.
|
32
|
-
subject.caps.
|
31
|
+
expect(subject).to respond_to :caps
|
32
|
+
expect(subject.caps).to be_kind_of Blather::Stanza::Capabilities
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#setup' do
|
36
36
|
it 'can be setup' do
|
37
|
-
subject.
|
38
|
-
subject.setup('me@me.com', 'pass').
|
37
|
+
expect(subject).to respond_to :setup
|
38
|
+
expect(subject.setup('me@me.com', 'pass')).to eq(subject)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'knows if it has been setup' do
|
42
|
-
subject.
|
43
|
-
subject.
|
42
|
+
expect(subject).to respond_to :setup?
|
43
|
+
expect(subject).not_to be_setup
|
44
44
|
subject.setup 'me@me.com', 'pass'
|
45
|
-
subject.
|
45
|
+
expect(subject).to be_setup
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'cannot be run before being setup' do
|
49
|
-
|
49
|
+
expect { subject.run }.to raise_error RuntimeError
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'starts up a Component connection when setup without a node' do
|
@@ -71,7 +71,7 @@ describe Blather::Client do
|
|
71
71
|
subject { Blather::Client.setup(jid, password, nil, nil, nil, nil, :workqueue_count => queue_size) }
|
72
72
|
|
73
73
|
it 'sets the queue size on the client' do
|
74
|
-
subject.queue_size.
|
74
|
+
expect(subject.queue_size).to eq(queue_size)
|
75
75
|
end
|
76
76
|
|
77
77
|
describe 'receiving data' do
|
@@ -81,7 +81,7 @@ describe Blather::Client do
|
|
81
81
|
let(:queue_size) { 0 }
|
82
82
|
|
83
83
|
it "has no handler queue" do
|
84
|
-
subject.handler_queue.
|
84
|
+
expect(subject.handler_queue).to be_nil
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'handles the data immediately' do
|
@@ -94,7 +94,7 @@ describe Blather::Client do
|
|
94
94
|
let(:queue_size) { 4 }
|
95
95
|
|
96
96
|
it 'enqueues the data on the handler queue' do
|
97
|
-
subject.handler_queue.expects(
|
97
|
+
subject.handler_queue.expects(:perform_async).with(stanza)
|
98
98
|
subject.receive_data stanza
|
99
99
|
end
|
100
100
|
end
|
@@ -103,21 +103,21 @@ describe Blather::Client do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'knows if it is disconnected' do
|
106
|
-
subject.
|
107
|
-
subject.
|
106
|
+
expect(subject).to respond_to :connected?
|
107
|
+
expect(subject).not_to be_connected
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'knows if it is connected' do
|
111
111
|
stream.expects(:stopped?).returns false
|
112
112
|
subject.setup 'me.com', 'secret'
|
113
113
|
subject.post_init stream, Blather::JID.new('me.com')
|
114
|
-
subject.
|
114
|
+
expect(subject).to be_connected
|
115
115
|
end
|
116
116
|
|
117
117
|
describe 'if it has been setup but not connected yet' do
|
118
118
|
it 'should consider itself disconnected' do
|
119
119
|
subject.setup 'me.com', 'secret'
|
120
|
-
subject.
|
120
|
+
expect(subject).not_to be_connected
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
@@ -158,18 +158,23 @@ describe Blather::Client do
|
|
158
158
|
stream.stubs(:close_connection_after_writing)
|
159
159
|
subject.handler_queue.expects(:shutdown)
|
160
160
|
subject.close
|
161
|
+
expect(instance_variable_get(:@handler_queue)).to be_nil
|
161
162
|
end
|
162
163
|
|
163
164
|
it 'forces the work queue to be re-created when referenced' do
|
164
165
|
stream.stubs(:close_connection_after_writing)
|
165
166
|
subject.close
|
166
167
|
|
167
|
-
fake_queue = stub('
|
168
|
-
|
169
|
-
|
168
|
+
fake_queue = stub('Blather::Client::Job subclass')
|
169
|
+
Class.expects(:new)
|
170
|
+
.with(Blather::Client::Job)
|
170
171
|
.returns(fake_queue)
|
172
|
+
fake_queue.expects(:client=)
|
173
|
+
.with(subject)
|
174
|
+
fake_queue.expects(:workers)
|
175
|
+
.with(subject.queue_size)
|
171
176
|
|
172
|
-
subject.handler_queue.
|
177
|
+
expect(subject.handler_queue).to eq(fake_queue)
|
173
178
|
end
|
174
179
|
end
|
175
180
|
end
|
@@ -235,7 +240,7 @@ describe Blather::Client do
|
|
235
240
|
response.expects(:call)
|
236
241
|
subject.expects(:write).with do |s|
|
237
242
|
subject.receive_data stanza
|
238
|
-
s.
|
243
|
+
expect(s).to eq(stanza)
|
239
244
|
end
|
240
245
|
subject.write_with_handler(stanza) { |_| response.call }
|
241
246
|
end
|
@@ -317,24 +322,24 @@ describe Blather::Client do
|
|
317
322
|
|
318
323
|
it 'updates the state when not sending to a Blather::JID' do
|
319
324
|
stream.stubs(:write)
|
320
|
-
subject.status.
|
325
|
+
expect(subject.status).not_to equal :away
|
321
326
|
subject.status = :away, 'message'
|
322
|
-
subject.status.
|
327
|
+
expect(subject.status).to eq(:away)
|
323
328
|
end
|
324
329
|
|
325
330
|
it 'does not update the state when sending to a Blather::JID' do
|
326
331
|
stream.stubs(:write)
|
327
|
-
subject.status.
|
332
|
+
expect(subject.status).not_to equal :away
|
328
333
|
subject.status = :away, 'message', 'me@me.com'
|
329
|
-
subject.status.
|
334
|
+
expect(subject.status).not_to equal :away
|
330
335
|
end
|
331
336
|
|
332
337
|
it 'writes the new status to the stream' do
|
333
338
|
Blather::Stanza::Presence::Status.stubs(:next_id).returns 0
|
334
339
|
status = [:away, 'message']
|
335
340
|
stream.expects(:send).with do |s|
|
336
|
-
s.
|
337
|
-
s.to_s.
|
341
|
+
expect(s).to be_kind_of Blather::Stanza::Presence::Status
|
342
|
+
expect(s.to_s).to eq(Blather::Stanza::Presence::Status.new(*status).to_s)
|
338
343
|
end
|
339
344
|
subject.status = status
|
340
345
|
end
|
@@ -343,7 +348,7 @@ describe Blather::Client do
|
|
343
348
|
describe 'default handlers' do
|
344
349
|
it 're-raises errors' do
|
345
350
|
err = Blather::BlatherError.new
|
346
|
-
|
351
|
+
expect { subject.receive_data err }.to raise_error Blather::BlatherError
|
347
352
|
end
|
348
353
|
|
349
354
|
# it 'responds to iq:get with a "service-unavailable" error' do
|
@@ -370,7 +375,7 @@ describe Blather::Client do
|
|
370
375
|
it 'responds to s2c pings with a pong' do
|
371
376
|
ping = Blather::Stanza::Iq::Ping.new :get
|
372
377
|
pong = ping.reply
|
373
|
-
subject.expects(:write).with { |n| n.to_s.
|
378
|
+
subject.expects(:write).with { |n| expect(n.to_s).to eq(pong.to_s) }
|
374
379
|
subject.receive_data ping
|
375
380
|
end
|
376
381
|
|
@@ -444,7 +449,7 @@ describe Blather::Client do
|
|
444
449
|
end
|
445
450
|
|
446
451
|
it 'sends a request for the roster when post_init is called' do
|
447
|
-
stream.expects(:send).with { |stanza| stanza.
|
452
|
+
stream.expects(:send).with { |stanza| expect(stanza).to be_kind_of Blather::Stanza::Iq::Roster }
|
448
453
|
subject.post_init stream, Blather::JID.new('n@d/r')
|
449
454
|
end
|
450
455
|
|
@@ -486,7 +491,7 @@ describe Blather::Client do
|
|
486
491
|
|
487
492
|
describe 'filters' do
|
488
493
|
it 'raises an error when an invalid filter type is registered' do
|
489
|
-
|
494
|
+
expect { subject.register_filter(:invalid) {} }.to raise_error RuntimeError
|
490
495
|
end
|
491
496
|
|
492
497
|
it 'can be guarded' do
|
@@ -510,11 +515,11 @@ describe Blather::Client do
|
|
510
515
|
it 'runs them in order' do
|
511
516
|
stanza = Blather::Stanza::Iq.new
|
512
517
|
count = 0
|
513
|
-
subject.register_filter(:before) { |_| count.
|
514
|
-
subject.register_filter(:before) { |_| count.
|
515
|
-
subject.register_handler(:iq) { |_| count.
|
516
|
-
subject.register_filter(:after) { |_| count.
|
517
|
-
subject.register_filter(:after) { |_| count.
|
518
|
+
subject.register_filter(:before) { |_| expect(count).to eq(0); count = 1 }
|
519
|
+
subject.register_filter(:before) { |_| expect(count).to eq(1); count = 2 }
|
520
|
+
subject.register_handler(:iq) { |_| expect(count).to eq(2); count = 3 }
|
521
|
+
subject.register_filter(:after) { |_| expect(count).to eq(3); count = 4 }
|
522
|
+
subject.register_filter(:after) { |_| expect(count).to eq(4) }
|
518
523
|
subject.receive_data stanza
|
519
524
|
end
|
520
525
|
|
@@ -659,9 +664,9 @@ describe Blather::Client do
|
|
659
664
|
|
660
665
|
it 'can be an xpath and will send the result to the handler' do
|
661
666
|
response.expects(:call).with do |stanza, xpath|
|
662
|
-
xpath.
|
663
|
-
xpath.
|
664
|
-
stanza.
|
667
|
+
expect(xpath).to be_instance_of Nokogiri::XML::NodeSet
|
668
|
+
expect(xpath).not_to be_empty
|
669
|
+
expect(stanza).to eq(stanza)
|
665
670
|
end
|
666
671
|
subject.register_handler(:iq, "/iq[@id='#{stanza.id}']") { |stanza, xpath| response.call stanza, xpath }
|
667
672
|
subject.receive_data stanza
|
@@ -670,16 +675,16 @@ describe Blather::Client do
|
|
670
675
|
it 'can be an xpath with namespaces and will send the result to the handler' do
|
671
676
|
stanza = Blather::Stanza.parse('<message><foo xmlns="http://bar.com"></message>')
|
672
677
|
response.expects(:call).with do |stanza, xpath|
|
673
|
-
xpath.
|
674
|
-
xpath.
|
675
|
-
stanza.
|
678
|
+
expect(xpath).to be_instance_of Nokogiri::XML::NodeSet
|
679
|
+
expect(xpath).not_to be_empty
|
680
|
+
expect(stanza).to eq(stanza)
|
676
681
|
end
|
677
682
|
subject.register_handler(:message, "/message/bar:foo", :bar => 'http://bar.com') { |stanza, xpath| response.call stanza, xpath }
|
678
683
|
subject.receive_data stanza
|
679
684
|
end
|
680
685
|
|
681
686
|
it 'raises an error when a bad guard is tried' do
|
682
|
-
|
687
|
+
expect { subject.register_handler(:iq, 0) {} }.to raise_error RuntimeError
|
683
688
|
end
|
684
689
|
end
|
685
690
|
|
@@ -687,51 +692,51 @@ describe Blather::Client do
|
|
687
692
|
let(:caps) { subject.caps }
|
688
693
|
|
689
694
|
it 'must be of type result' do
|
690
|
-
caps.
|
691
|
-
caps.type.
|
695
|
+
expect(caps).to respond_to :type
|
696
|
+
expect(caps.type).to eq(:result)
|
692
697
|
end
|
693
698
|
|
694
699
|
it 'can have a client node set' do
|
695
|
-
caps.
|
700
|
+
expect(caps).to respond_to :node=
|
696
701
|
caps.node = "somenode"
|
697
702
|
end
|
698
703
|
|
699
704
|
it 'provides a client node reader' do
|
700
|
-
caps.
|
705
|
+
expect(caps).to respond_to :node
|
701
706
|
caps.node = "somenode"
|
702
|
-
caps.node.
|
707
|
+
expect(caps.node).to eq("somenode##{caps.ver}")
|
703
708
|
end
|
704
709
|
|
705
710
|
it 'can have identities set' do
|
706
|
-
caps.
|
711
|
+
expect(caps).to respond_to :identities=
|
707
712
|
caps.identities = [{:name => "name", :type => "type", :category => "cat"}]
|
708
713
|
end
|
709
714
|
|
710
715
|
it 'provides an identities reader' do
|
711
|
-
caps.
|
716
|
+
expect(caps).to respond_to :identities
|
712
717
|
caps.identities = [{:name => "name", :type => "type", :category => "cat"}]
|
713
|
-
caps.identities.
|
718
|
+
expect(caps.identities).to eq([Blather::Stanza::Iq::DiscoInfo::Identity.new({:name => "name", :type => "type", :category => "cat"})])
|
714
719
|
end
|
715
720
|
|
716
721
|
it 'can have features set' do
|
717
|
-
caps.
|
718
|
-
caps.features.size.
|
722
|
+
expect(caps).to respond_to :features=
|
723
|
+
expect(caps.features.size).to eq(0)
|
719
724
|
caps.features = ["feature1"]
|
720
|
-
caps.features.size.
|
725
|
+
expect(caps.features.size).to eq(1)
|
721
726
|
caps.features += [Blather::Stanza::Iq::DiscoInfo::Feature.new("feature2")]
|
722
|
-
caps.features.size.
|
727
|
+
expect(caps.features.size).to eq(2)
|
723
728
|
caps.features = nil
|
724
|
-
caps.features.size.
|
729
|
+
expect(caps.features.size).to eq(0)
|
725
730
|
end
|
726
731
|
|
727
732
|
it 'provides a features reader' do
|
728
|
-
caps.
|
733
|
+
expect(caps).to respond_to :features
|
729
734
|
caps.features = %w{feature1 feature2}
|
730
|
-
caps.features.
|
735
|
+
expect(caps.features).to eq([Blather::Stanza::Iq::DiscoInfo::Feature.new("feature1"), Blather::Stanza::Iq::DiscoInfo::Feature.new("feature2")])
|
731
736
|
end
|
732
737
|
|
733
738
|
it 'provides a client ver reader' do
|
734
|
-
caps.
|
739
|
+
expect(caps).to respond_to :ver
|
735
740
|
caps.node = 'http://code.google.com/p/exodus'
|
736
741
|
caps.identities = [Blather::Stanza::Iq::DiscoInfo::Identity.new({:name => 'Exodus 0.9.1', :type => 'pc', :category => 'client'})]
|
737
742
|
caps.features = %w{
|
@@ -740,12 +745,12 @@ describe Blather::Client do
|
|
740
745
|
http://jabber.org/protocol/disco#items
|
741
746
|
http://jabber.org/protocol/muc
|
742
747
|
}
|
743
|
-
caps.ver.
|
744
|
-
caps.node.
|
748
|
+
expect(caps.ver).to eq('QgayPKawpkPSDYmwT/WM94uAlu0=')
|
749
|
+
expect(caps.node).to eq("http://code.google.com/p/exodus#QgayPKawpkPSDYmwT/WM94uAlu0=")
|
745
750
|
end
|
746
751
|
|
747
752
|
it 'can construct caps presence correctly' do
|
748
|
-
caps.
|
753
|
+
expect(caps).to respond_to :c
|
749
754
|
caps.node = 'http://code.google.com/p/exodus'
|
750
755
|
caps.identities = [Blather::Stanza::Iq::DiscoInfo::Identity.new({:name => 'Exodus 0.9.1', :type => 'pc', :category => 'client'})]
|
751
756
|
caps.features = %w{
|
@@ -754,7 +759,7 @@ describe Blather::Client do
|
|
754
759
|
http://jabber.org/protocol/disco#items
|
755
760
|
http://jabber.org/protocol/muc
|
756
761
|
}
|
757
|
-
Nokogiri::XML(caps.c.to_xml).to_s.
|
762
|
+
expect(Nokogiri::XML(caps.c.to_xml).to_s).to eq(Nokogiri::XML("<presence><c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"http://code.google.com/p/exodus\" ver=\"QgayPKawpkPSDYmwT/WM94uAlu0=\"/></presence>").to_s)
|
758
763
|
end
|
759
764
|
end
|
760
765
|
end
|