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
@@ -109,7 +109,7 @@ describe Blather::DSL do
|
|
109
109
|
it 'provides a << style writer that provides chaining' do
|
110
110
|
stanza = Blather::Stanza::Iq.new
|
111
111
|
@client.expects(:write).with stanza
|
112
|
-
(@dsl << stanza).
|
112
|
+
expect(@dsl << stanza).to eq(@dsl)
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'provides a writer' do
|
@@ -173,7 +173,7 @@ describe Blather::DSL do
|
|
173
173
|
end
|
174
174
|
|
175
175
|
it 'provides a caps set helper' do
|
176
|
-
@dsl.
|
176
|
+
expect(@dsl).to respond_to :set_caps
|
177
177
|
node = 'http://code.google.com/p/exodus'
|
178
178
|
identities = [Blather::Stanza::Iq::DiscoInfo::Identity.new({:name => 'Exodus 0.9.1', :type => 'pc', :category => 'client'})]
|
179
179
|
features = %w{
|
@@ -183,13 +183,13 @@ describe Blather::DSL do
|
|
183
183
|
http://jabber.org/protocol/muc
|
184
184
|
}
|
185
185
|
@dsl.set_caps node, identities, features
|
186
|
-
@client.caps.node.
|
187
|
-
@client.caps.identities.
|
188
|
-
@client.caps.features.map{ |f| f.var }.
|
186
|
+
expect(@client.caps.node).to eq("#{node}##{@client.caps.ver}")
|
187
|
+
expect(@client.caps.identities).to eq(identities)
|
188
|
+
expect(@client.caps.features.map{ |f| f.var }).to eq(features)
|
189
189
|
end
|
190
190
|
|
191
191
|
it 'provides a caps send helper' do
|
192
|
-
@dsl.
|
192
|
+
expect(@dsl).to respond_to :send_caps
|
193
193
|
@client.caps.node = 'http://code.google.com/p/exodus'
|
194
194
|
@client.caps.identities = [Blather::Stanza::Iq::DiscoInfo::Identity.new({:name => 'Exodus 0.9.1', :type => 'pc', :category => 'client'})]
|
195
195
|
@client.caps.features = %w{
|
@@ -260,8 +260,8 @@ describe Blather::DSL do
|
|
260
260
|
it 'has a pubsub helper set to the jid domain' do
|
261
261
|
jid = Blather::JID.new('jid@domain/resource')
|
262
262
|
@client.stubs(:jid).returns jid
|
263
|
-
@dsl.pubsub.
|
264
|
-
@dsl.pubsub.host.
|
263
|
+
expect(@dsl.pubsub).to be_instance_of Blather::DSL::PubSub
|
264
|
+
expect(@dsl.pubsub.host).to eq(jid.domain)
|
265
265
|
end
|
266
266
|
|
267
267
|
context "extending a module" do
|
@@ -291,7 +291,7 @@ describe Blather::DSL do
|
|
291
291
|
|
292
292
|
it "should override the handlers" do
|
293
293
|
target = CollisionTarget.new
|
294
|
-
target.presence.
|
294
|
+
expect(target.presence).to be :ghostly
|
295
295
|
end
|
296
296
|
end
|
297
297
|
end
|
@@ -10,9 +10,9 @@ end
|
|
10
10
|
|
11
11
|
describe Blather::SASLError do
|
12
12
|
it 'can import a node' do
|
13
|
-
Blather::SASLError.
|
13
|
+
expect(Blather::SASLError).to respond_to :import
|
14
14
|
e = Blather::SASLError.import sasl_error_node
|
15
|
-
e.
|
15
|
+
expect(e).to be_kind_of Blather::SASLError
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'each XMPP SASL error type' do
|
@@ -26,7 +26,7 @@ describe Blather::SASLError do
|
|
26
26
|
].each do |error_type|
|
27
27
|
it "handles the name for #{error_type}" do
|
28
28
|
e = Blather::SASLError.import sasl_error_node(error_type)
|
29
|
-
e.name.
|
29
|
+
expect(e.name).to eq(error_type.gsub('-','_').to_sym)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -24,20 +24,20 @@ end
|
|
24
24
|
|
25
25
|
describe Blather::StanzaError do
|
26
26
|
it 'can import a node' do
|
27
|
-
Blather::StanzaError.
|
27
|
+
expect(Blather::StanzaError).to respond_to :import
|
28
28
|
e = Blather::StanzaError.import stanza_error_node
|
29
|
-
e.
|
29
|
+
expect(e).to be_kind_of Blather::StanzaError
|
30
30
|
end
|
31
31
|
|
32
32
|
describe 'valid types' do
|
33
33
|
before { @original = Blather::Stanza::Message.new 'error@jabber.local', 'test message', :error }
|
34
34
|
|
35
35
|
it 'ensures type is one of Stanza::Message::VALID_TYPES' do
|
36
|
-
|
36
|
+
expect { Blather::StanzaError.new @original, :gone, :invalid_type_name }.to raise_error(Blather::ArgumentError)
|
37
37
|
|
38
38
|
Blather::StanzaError::VALID_TYPES.each do |valid_type|
|
39
39
|
msg = Blather::StanzaError.new @original, :gone, valid_type
|
40
|
-
msg.type.
|
40
|
+
expect(msg.type).to eq(valid_type)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -51,48 +51,48 @@ describe Blather::StanzaError do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'provides a type attribute' do
|
54
|
-
@err.
|
55
|
-
@err.type.
|
54
|
+
expect(@err).to respond_to :type
|
55
|
+
expect(@err.type).to eq(@type.to_sym)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'provides a name attribute' do
|
59
|
-
@err.
|
60
|
-
@err.name.
|
59
|
+
expect(@err).to respond_to :name
|
60
|
+
expect(@err.name).to eq(@err_name.gsub('-','_').to_sym)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'provides a text attribute' do
|
64
|
-
@err.
|
65
|
-
@err.text.
|
64
|
+
expect(@err).to respond_to :text
|
65
|
+
expect(@err.text).to eq(@msg)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'provides a reader to the original node' do
|
69
|
-
@err.
|
70
|
-
@err.original.
|
69
|
+
expect(@err).to respond_to :original
|
70
|
+
expect(@err.original).to be_instance_of Blather::Stanza::Message
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'provides an extras attribute' do
|
74
|
-
@err.
|
75
|
-
@err.extras.
|
76
|
-
@err.extras.first.element_name.
|
74
|
+
expect(@err).to respond_to :extras
|
75
|
+
expect(@err.extras).to be_instance_of Array
|
76
|
+
expect(@err.extras.first.element_name).to eq('extra-error')
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'describes itself' do
|
80
|
-
@err.to_s.
|
81
|
-
@err.to_s.
|
80
|
+
expect(@err.to_s).to match(/#{@err_name}/)
|
81
|
+
expect(@err.to_s).to match(/#{@msg}/)
|
82
82
|
|
83
|
-
@err.inspect.
|
84
|
-
@err.inspect.
|
83
|
+
expect(@err.inspect).to match(/#{@err_name}/)
|
84
|
+
expect(@err.inspect).to match(/#{@msg}/)
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'can be turned into xml' do
|
88
|
-
@err.
|
88
|
+
expect(@err).to respond_to :to_xml
|
89
89
|
doc = parse_stanza @err.to_xml
|
90
90
|
|
91
|
-
doc.xpath("/message[@from='error@jabber.local' and @type='error']").
|
92
|
-
doc.xpath("/message/error").
|
93
|
-
doc.xpath("/message/error/err_ns:internal-server-error", :err_ns => Blather::StanzaError::STANZA_ERR_NS).
|
94
|
-
doc.xpath("/message/error/err_ns:text[.='the server has experienced a misconfiguration']", :err_ns => Blather::StanzaError::STANZA_ERR_NS).
|
95
|
-
doc.xpath("/message/error/extra_ns:extra-error[.='Blather Error']", :extra_ns => 'blather:stanza:error').
|
91
|
+
expect(doc.xpath("/message[@from='error@jabber.local' and @type='error']")).not_to be_empty
|
92
|
+
expect(doc.xpath("/message/error")).not_to be_empty
|
93
|
+
expect(doc.xpath("/message/error/err_ns:internal-server-error", :err_ns => Blather::StanzaError::STANZA_ERR_NS)).not_to be_empty
|
94
|
+
expect(doc.xpath("/message/error/err_ns:text[.='the server has experienced a misconfiguration']", :err_ns => Blather::StanzaError::STANZA_ERR_NS)).not_to be_empty
|
95
|
+
expect(doc.xpath("/message/error/extra_ns:extra-error[.='Blather Error']", :extra_ns => 'blather:stanza:error')).not_to be_empty
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -122,7 +122,7 @@ describe Blather::StanzaError do
|
|
122
122
|
].each do |error_type|
|
123
123
|
it "handles the name for #{error_type}" do
|
124
124
|
e = Blather::StanzaError.import stanza_error_node(:cancel, error_type)
|
125
|
-
e.name.
|
125
|
+
expect(e.name).to eq(error_type.gsub('-','_').to_sym)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
end
|
@@ -23,13 +23,13 @@ end
|
|
23
23
|
describe 'Blather::StreamError' do
|
24
24
|
it 'can import a node' do
|
25
25
|
err = stream_error_node 'internal-server-error', 'the message'
|
26
|
-
Blather::StreamError.
|
26
|
+
expect(Blather::StreamError).to respond_to :import
|
27
27
|
e = Blather::StreamError.import err
|
28
|
-
e.
|
28
|
+
expect(e).to be_kind_of Blather::StreamError
|
29
29
|
|
30
|
-
e.name.
|
31
|
-
e.text.
|
32
|
-
e.extras.
|
30
|
+
expect(e.name).to eq(:internal_server_error)
|
31
|
+
expect(e.text).to eq('the message')
|
32
|
+
expect(e.extras).to eq(err.find('descendant::*[name()="extra-error"]', 'blather:stream:error').map {|n|n})
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -41,36 +41,36 @@ describe 'Blather::StreamError when instantiated' do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'provides a err_name attribute' do
|
44
|
-
@err.
|
45
|
-
@err.name.
|
44
|
+
expect(@err).to respond_to :name
|
45
|
+
expect(@err.name).to eq(@err_name.gsub('-','_').to_sym)
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'provides a text attribute' do
|
49
|
-
@err.
|
50
|
-
@err.text.
|
49
|
+
expect(@err).to respond_to :text
|
50
|
+
expect(@err.text).to eq(@msg)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'provides an extras attribute' do
|
54
|
-
@err.
|
55
|
-
@err.extras.
|
56
|
-
@err.extras.size.
|
57
|
-
@err.extras.first.element_name.
|
54
|
+
expect(@err).to respond_to :extras
|
55
|
+
expect(@err.extras).to be_instance_of Array
|
56
|
+
expect(@err.extras.size).to eq(1)
|
57
|
+
expect(@err.extras.first.element_name).to eq('extra-error')
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'describes itself' do
|
61
|
-
@err.to_s.
|
62
|
-
@err.to_s.
|
61
|
+
expect(@err.to_s).to match(/#{@type}/)
|
62
|
+
expect(@err.to_s).to match(/#{@msg}/)
|
63
63
|
|
64
|
-
@err.inspect.
|
65
|
-
@err.inspect.
|
64
|
+
expect(@err.inspect).to match(/#{@type}/)
|
65
|
+
expect(@err.inspect).to match(/#{@msg}/)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'can be turned into xml' do
|
69
|
-
@err.
|
69
|
+
expect(@err).to respond_to :to_xml
|
70
70
|
doc = parse_stanza @err.to_xml
|
71
|
-
doc.xpath("//err_ns:internal-server-error", :err_ns => Blather::StreamError::STREAM_ERR_NS).
|
72
|
-
doc.xpath("//err_ns:text[.='the server has experienced a misconfiguration']", :err_ns => Blather::StreamError::STREAM_ERR_NS).
|
73
|
-
doc.xpath("//err_ns:extra-error[.='Blather Error']", :err_ns => 'blather:stream:error').
|
71
|
+
expect(doc.xpath("//err_ns:internal-server-error", :err_ns => Blather::StreamError::STREAM_ERR_NS)).not_to be_empty
|
72
|
+
expect(doc.xpath("//err_ns:text[.='the server has experienced a misconfiguration']", :err_ns => Blather::StreamError::STREAM_ERR_NS)).not_to be_empty
|
73
|
+
expect(doc.xpath("//err_ns:extra-error[.='Blather Error']", :err_ns => 'blather:stream:error')).not_to be_empty
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -102,7 +102,7 @@ describe 'Each XMPP stream error type' do
|
|
102
102
|
].each do |error_type|
|
103
103
|
it "handles the name for #{error_type}" do
|
104
104
|
e = Blather::StreamError.import stream_error_node(error_type)
|
105
|
-
e.name.
|
105
|
+
expect(e.name).to eq(error_type.gsub('-','_').to_sym)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
data/spec/blather/errors_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Blather::BlatherError do
|
4
4
|
it 'is handled by :error' do
|
5
|
-
Blather::BlatherError.new.handler_hierarchy.
|
5
|
+
expect(Blather::BlatherError.new.handler_hierarchy).to eq([:error])
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -10,12 +10,12 @@ describe 'Blather::ParseError' do
|
|
10
10
|
before { @error = Blather::ParseError.new('</generate-parse-error>"') }
|
11
11
|
|
12
12
|
it 'is registers with the handler hierarchy' do
|
13
|
-
@error.handler_hierarchy.
|
13
|
+
expect(@error.handler_hierarchy).to eq([:parse_error, :error])
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'contains the error message' do
|
17
|
-
@error.
|
18
|
-
@error.message.
|
17
|
+
expect(@error).to respond_to :message
|
18
|
+
expect(@error.message).to eq('</generate-parse-error>"')
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -23,11 +23,11 @@ describe 'Blather::UnknownResponse' do
|
|
23
23
|
before { @error = Blather::UnknownResponse.new(Blather::XMPPNode.new('foo-bar')) }
|
24
24
|
|
25
25
|
it 'is registers with the handler hierarchy' do
|
26
|
-
@error.handler_hierarchy.
|
26
|
+
expect(@error.handler_hierarchy).to eq([:unknown_response_error, :error])
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'holds on to a copy of the failure node' do
|
30
|
-
@error.
|
31
|
-
@error.node.element_name.
|
30
|
+
expect(@error).to respond_to :node
|
31
|
+
expect(@error.node.element_name).to eq('foo-bar')
|
32
32
|
end
|
33
33
|
end
|
@@ -47,7 +47,7 @@ describe Blather::FileTransfer do
|
|
47
47
|
iq = Blather::XMPPNode.parse(si_xml)
|
48
48
|
|
49
49
|
@client.stubs(:write).with do |answer|
|
50
|
-
answer.si.feature.x.field('stream-method').value.
|
50
|
+
expect(answer.si.feature.x.field('stream-method').value).to eq(Blather::Stanza::Iq::Ibb::NS_IBB)
|
51
51
|
true
|
52
52
|
end
|
53
53
|
|
@@ -61,7 +61,7 @@ describe Blather::FileTransfer do
|
|
61
61
|
iq = Blather::XMPPNode.parse(si_xml)
|
62
62
|
|
63
63
|
@client.stubs(:write).with do |answer|
|
64
|
-
answer.si.feature.x.field('stream-method').value.
|
64
|
+
expect(answer.si.feature.x.field('stream-method').value).to eq(Blather::Stanza::Iq::S5b::NS_S5B)
|
65
65
|
true
|
66
66
|
end
|
67
67
|
|
@@ -75,7 +75,7 @@ describe Blather::FileTransfer do
|
|
75
75
|
iq = Blather::XMPPNode.parse(si_xml)
|
76
76
|
|
77
77
|
@client.stubs(:write).with do |answer|
|
78
|
-
answer.si.feature.x.field('stream-method').value.
|
78
|
+
expect(answer.si.feature.x.field('stream-method').value).to eq(Blather::Stanza::Iq::S5b::NS_S5B)
|
79
79
|
true
|
80
80
|
end
|
81
81
|
|
@@ -90,8 +90,8 @@ describe Blather::FileTransfer do
|
|
90
90
|
iq = Blather::XMPPNode.parse(si_xml)
|
91
91
|
|
92
92
|
@client.stubs(:write).with do |answer|
|
93
|
-
answer.find_first('error')['type'].
|
94
|
-
answer.find_first('.//ns:no-valid-streams', :ns => 'http://jabber.org/protocol/si').
|
93
|
+
expect(answer.find_first('error')['type']).to eq("cancel")
|
94
|
+
expect(answer.find_first('.//ns:no-valid-streams', :ns => 'http://jabber.org/protocol/si')).not_to be_nil
|
95
95
|
true
|
96
96
|
end
|
97
97
|
|
@@ -105,9 +105,9 @@ describe Blather::FileTransfer do
|
|
105
105
|
iq = Blather::XMPPNode.parse(si_xml)
|
106
106
|
|
107
107
|
@client.stubs(:write).with do |answer|
|
108
|
-
answer.find_first('error')['type'].
|
109
|
-
answer.find_first('.//ns:forbidden', :ns => 'urn:ietf:params:xml:ns:xmpp-stanzas').
|
110
|
-
answer.find_first('.//ns:text', :ns => 'urn:ietf:params:xml:ns:xmpp-stanzas').content.
|
108
|
+
expect(answer.find_first('error')['type']).to eq("cancel")
|
109
|
+
expect(answer.find_first('.//ns:forbidden', :ns => 'urn:ietf:params:xml:ns:xmpp-stanzas')).not_to be_nil
|
110
|
+
expect(answer.find_first('.//ns:text', :ns => 'urn:ietf:params:xml:ns:xmpp-stanzas').content).to eq("Offer declined")
|
111
111
|
true
|
112
112
|
end
|
113
113
|
|
@@ -130,6 +130,6 @@ describe Blather::FileTransfer do
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
133
|
-
|
133
|
+
expect { TestS5B.new }.not_to raise_error
|
134
134
|
end
|
135
135
|
end
|
data/spec/blather/jid_spec.rb
CHANGED
@@ -3,85 +3,85 @@ require 'spec_helper'
|
|
3
3
|
describe Blather::JID do
|
4
4
|
it 'does nothing if creaded from Blather::JID' do
|
5
5
|
jid = Blather::JID.new 'n@d/r'
|
6
|
-
Blather::JID.new(jid).object_id.
|
6
|
+
expect(Blather::JID.new(jid).object_id).to eq(jid.object_id)
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'creates a new Blather::JID from (n,d,r)' do
|
10
10
|
jid = Blather::JID.new('n', 'd', 'r')
|
11
|
-
jid.node.
|
12
|
-
jid.domain.
|
13
|
-
jid.resource.
|
11
|
+
expect(jid.node).to eq('n')
|
12
|
+
expect(jid.domain).to eq('d')
|
13
|
+
expect(jid.resource).to eq('r')
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'creates a new Blather::JID from (n,d)' do
|
17
17
|
jid = Blather::JID.new('n', 'd')
|
18
|
-
jid.node.
|
19
|
-
jid.domain.
|
18
|
+
expect(jid.node).to eq('n')
|
19
|
+
expect(jid.domain).to eq('d')
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'creates a new Blather::JID from (n@d)' do
|
23
23
|
jid = Blather::JID.new('n@d')
|
24
|
-
jid.node.
|
25
|
-
jid.domain.
|
24
|
+
expect(jid.node).to eq('n')
|
25
|
+
expect(jid.domain).to eq('d')
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'creates a new Blather::JID from (n@d/r)' do
|
29
29
|
jid = Blather::JID.new('n@d/r')
|
30
|
-
jid.node.
|
31
|
-
jid.domain.
|
32
|
-
jid.resource.
|
30
|
+
expect(jid.node).to eq('n')
|
31
|
+
expect(jid.domain).to eq('d')
|
32
|
+
expect(jid.resource).to eq('r')
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'requires at least a node' do
|
36
|
-
|
36
|
+
expect { Blather::JID.new }.to raise_error ::ArgumentError
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'ensures length of node is no more than 1023 characters' do
|
40
|
-
|
40
|
+
expect { Blather::JID.new('n'*1024) }.to raise_error Blather::ArgumentError
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'ensures length of domain is no more than 1023 characters' do
|
44
|
-
|
44
|
+
expect { Blather::JID.new('n', 'd'*1024) }.to raise_error Blather::ArgumentError
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'ensures length of resource is no more than 1023 characters' do
|
48
|
-
|
48
|
+
expect { Blather::JID.new('n', 'd', 'r'*1024) }.to raise_error Blather::ArgumentError
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'compares Blather::JIDs' do
|
52
|
-
(Blather::JID.new('a@b/c') <=> Blather::JID.new('d@e/f')).
|
53
|
-
(Blather::JID.new('a@b/c') <=> Blather::JID.new('a@b/c')).
|
54
|
-
(Blather::JID.new('d@e/f') <=> Blather::JID.new('a@b/c')).
|
52
|
+
expect(Blather::JID.new('a@b/c') <=> Blather::JID.new('d@e/f')).to eq(-1)
|
53
|
+
expect(Blather::JID.new('a@b/c') <=> Blather::JID.new('a@b/c')).to eq(0)
|
54
|
+
expect(Blather::JID.new('d@e/f') <=> Blather::JID.new('a@b/c')).to eq(1)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'checks for equality' do
|
58
|
-
(Blather::JID.new('n@d/r') == Blather::JID.new('n@d/r')).
|
59
|
-
Blather::JID.new('n@d/r').eql?(Blather::JID.new('n@d/r')).
|
58
|
+
expect(Blather::JID.new('n@d/r') == Blather::JID.new('n@d/r')).to eq(true)
|
59
|
+
expect(Blather::JID.new('n@d/r').eql?(Blather::JID.new('n@d/r'))).to eq(true)
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'will strip' do
|
63
63
|
jid = Blather::JID.new('n@d/r')
|
64
|
-
jid.stripped.
|
65
|
-
jid.
|
64
|
+
expect(jid.stripped).to eq(Blather::JID.new('n@d'))
|
65
|
+
expect(jid).to eq(Blather::JID.new('n@d/r'))
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'will strip itself' do
|
69
69
|
jid = Blather::JID.new('n@d/r')
|
70
70
|
jid.strip!
|
71
|
-
jid.
|
71
|
+
expect(jid).to eq(Blather::JID.new('n@d'))
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'has a string representation' do
|
75
|
-
Blather::JID.new('n@d/r').to_s.
|
76
|
-
Blather::JID.new('n', 'd', 'r').to_s.
|
77
|
-
Blather::JID.new('n', 'd').to_s.
|
75
|
+
expect(Blather::JID.new('n@d/r').to_s).to eq('n@d/r')
|
76
|
+
expect(Blather::JID.new('n', 'd', 'r').to_s).to eq('n@d/r')
|
77
|
+
expect(Blather::JID.new('n', 'd').to_s).to eq('n@d')
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'provides a #stripped? helper' do
|
81
81
|
jid = Blather::JID.new 'a@b/c'
|
82
|
-
jid.
|
83
|
-
jid.stripped
|
82
|
+
expect(jid).to respond_to :stripped?
|
83
|
+
expect(jid.stripped?).not_to equal true
|
84
84
|
jid.strip!
|
85
|
-
jid.stripped
|
85
|
+
expect(jid.stripped?).to eq(true)
|
86
86
|
end
|
87
87
|
end
|