blather 0.6.2 → 0.7.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.
- data/.rspec +3 -0
- data/.travis.yml +1 -8
- data/CHANGELOG.md +230 -0
- data/Guardfile +4 -4
- data/README.md +2 -8
- data/Rakefile +14 -27
- data/blather.gemspec +8 -18
- data/lib/blather.rb +1 -0
- data/lib/blather/client/client.rb +8 -0
- data/lib/blather/roster.rb +7 -0
- data/lib/blather/stanza/iq/roster.rb +1 -1
- data/lib/blather/stanza/message/muc_user.rb +2 -0
- data/lib/blather/stanza/muc/muc_user_base.rb +4 -3
- data/lib/blather/stanza/presence.rb +12 -14
- data/lib/blather/stanza/presence/c.rb +58 -62
- data/lib/blather/stanza/presence/muc.rb +14 -10
- data/lib/blather/stanza/presence/muc_user.rb +47 -36
- data/lib/blather/stanza/presence/status.rb +106 -101
- data/lib/blather/stanza/presence/subscription.rb +59 -60
- data/lib/blather/stream.rb +1 -3
- data/lib/blather/stream/features/resource.rb +0 -1
- data/lib/blather/version.rb +1 -2
- data/lib/blather/xmpp_node.rb +24 -3
- data/spec/blather/client/client_spec.rb +64 -64
- data/spec/blather/client/dsl/pubsub_spec.rb +127 -127
- data/spec/blather/client/dsl_spec.rb +11 -11
- 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 +16 -18
- 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 -57
- data/spec/blather/stanza/discos/disco_items_spec.rb +33 -33
- data/spec/blather/stanza/iq/command_spec.rb +57 -57
- data/spec/blather/stanza/iq/ibb_spec.rb +27 -39
- data/spec/blather/stanza/iq/ping_spec.rb +13 -9
- data/spec/blather/stanza/iq/query_spec.rb +16 -16
- data/spec/blather/stanza/iq/roster_spec.rb +29 -30
- data/spec/blather/stanza/iq/s5b_spec.rb +10 -13
- data/spec/blather/stanza/iq/si_spec.rb +20 -23
- data/spec/blather/stanza/iq/vcard_spec.rb +22 -25
- data/spec/blather/stanza/iq_spec.rb +12 -12
- data/spec/blather/stanza/message/muc_user_spec.rb +36 -36
- data/spec/blather/stanza/message_spec.rb +56 -56
- data/spec/blather/stanza/presence/c_spec.rb +17 -7
- data/spec/blather/stanza/presence/muc_spec.rb +8 -8
- data/spec/blather/stanza/presence/muc_user_spec.rb +23 -23
- data/spec/blather/stanza/presence/status_spec.rb +42 -30
- data/spec/blather/stanza/presence/subscription_spec.rb +22 -23
- data/spec/blather/stanza/presence_spec.rb +72 -34
- data/spec/blather/stanza/pubsub/affiliations_spec.rb +12 -12
- data/spec/blather/stanza/pubsub/create_spec.rb +10 -10
- data/spec/blather/stanza/pubsub/event_spec.rb +31 -31
- data/spec/blather/stanza/pubsub/items_spec.rb +21 -21
- data/spec/blather/stanza/pubsub/publish_spec.rb +21 -21
- data/spec/blather/stanza/pubsub/retract_spec.rb +20 -20
- 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 +11 -11
- 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 +16 -16
- data/spec/blather/stanza/x_spec.rb +53 -53
- data/spec/blather/stanza_spec.rb +39 -39
- data/spec/blather/stream/client_spec.rb +133 -133
- data/spec/blather/stream/component_spec.rb +7 -7
- data/spec/blather/stream/parser_spec.rb +24 -24
- data/spec/blather/stream/ssl_spec.rb +7 -7
- data/spec/blather/xmpp_node_spec.rb +17 -7
- data/spec/blather_spec.rb +4 -4
- data/spec/spec_helper.rb +6 -54
- metadata +53 -68
- data/CHANGELOG +0 -220
@@ -10,32 +10,36 @@ end
|
|
10
10
|
|
11
11
|
describe Blather::Stanza::Iq::Ping do
|
12
12
|
it 'registers itself' do
|
13
|
-
Blather::XMPPNode.class_from_registration(:ping, 'urn:xmpp:ping').
|
13
|
+
Blather::XMPPNode.class_from_registration(:ping, 'urn:xmpp:ping').should == Blather::Stanza::Iq::Ping
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'can be imported' do
|
17
|
-
|
18
|
-
node
|
19
|
-
node.must_be_instance_of Blather::Stanza::Iq::Ping
|
17
|
+
node = Blather::XMPPNode.parse ping_xml
|
18
|
+
node.should be_instance_of Blather::Stanza::Iq::Ping
|
20
19
|
end
|
21
20
|
|
22
21
|
it 'ensures a ping node is present on create' do
|
23
22
|
iq = Blather::Stanza::Iq::Ping.new
|
24
|
-
iq.xpath('ns:ping', :ns => 'urn:xmpp:ping').
|
23
|
+
iq.xpath('ns:ping', :ns => 'urn:xmpp:ping').should_not be_empty
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'ensures a ping node exists when calling #ping' do
|
28
27
|
iq = Blather::Stanza::Iq::Ping.new
|
29
28
|
iq.ping.remove
|
30
|
-
iq.xpath('ns:ping', :ns => 'urn:xmpp:ping').
|
29
|
+
iq.xpath('ns:ping', :ns => 'urn:xmpp:ping').should be_empty
|
31
30
|
|
32
|
-
iq.ping.
|
33
|
-
iq.xpath('ns:ping', :ns => 'urn:xmpp:ping').
|
31
|
+
iq.ping.should_not be_nil
|
32
|
+
iq.xpath('ns:ping', :ns => 'urn:xmpp:ping').should_not be_empty
|
34
33
|
end
|
35
34
|
|
36
35
|
it 'responds with an empty IQ' do
|
37
36
|
ping = Blather::Stanza::Iq::Ping.new :get, 'one@example.com', 'abc123'
|
38
37
|
ping.from = 'two@example.com'
|
39
|
-
|
38
|
+
expected_pong = Blather::Stanza::Iq::Ping.new(:result, 'two@example.com', 'abc123').tap do |pong|
|
39
|
+
pong.from = 'one@example.com'
|
40
|
+
end
|
41
|
+
reply = ping.reply
|
42
|
+
reply.should == expected_pong
|
43
|
+
reply.children.count.should == 0
|
40
44
|
end
|
41
45
|
end
|
@@ -2,63 +2,63 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Blather::Stanza::Iq::Query do
|
4
4
|
it 'registers itself' do
|
5
|
-
Blather::XMPPNode.class_from_registration(:query, nil).
|
5
|
+
Blather::XMPPNode.class_from_registration(:query, nil).should == Blather::Stanza::Iq::Query
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'can be imported' do
|
9
|
-
|
9
|
+
string = <<-XML
|
10
10
|
<iq from='juliet@example.com/balcony' type='set' id='roster_4'>
|
11
11
|
<query>
|
12
12
|
<item jid='nurse@example.com' subscription='remove'/>
|
13
13
|
</query>
|
14
14
|
</iq>
|
15
15
|
XML
|
16
|
-
Blather::XMPPNode.
|
16
|
+
Blather::XMPPNode.parse(string).should be_instance_of Blather::Stanza::Iq::Query
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'ensures a query node is present on create' do
|
20
20
|
query = Blather::Stanza::Iq::Query.new
|
21
|
-
query.xpath('query').
|
21
|
+
query.xpath('query').should_not be_empty
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'ensures a query node exists when calling #query' do
|
25
25
|
query = Blather::Stanza::Iq::Query.new
|
26
26
|
query.remove_child :query
|
27
|
-
query.xpath('query').
|
27
|
+
query.xpath('query').should be_empty
|
28
28
|
|
29
|
-
query.query.
|
30
|
-
query.xpath('query').
|
29
|
+
query.query.should_not be_nil
|
30
|
+
query.xpath('query').should_not be_empty
|
31
31
|
end
|
32
32
|
|
33
33
|
[:get, :set, :result, :error].each do |type|
|
34
34
|
it "can be set as \"#{type}\"" do
|
35
35
|
query = Blather::Stanza::Iq::Query.new type
|
36
|
-
query.type.
|
36
|
+
query.type.should == type
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'sets type to "result" on reply' do
|
41
41
|
query = Blather::Stanza::Iq::Query.new
|
42
|
-
query.type.
|
43
|
-
reply = query.reply.type.
|
42
|
+
query.type.should == :get
|
43
|
+
reply = query.reply.type.should == :result
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'sets type to "result" on reply!' do
|
47
47
|
query = Blather::Stanza::Iq::Query.new
|
48
|
-
query.type.
|
48
|
+
query.type.should == :get
|
49
49
|
query.reply!
|
50
|
-
query.type.
|
50
|
+
query.type.should == :result
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'can be registered under a namespace' do
|
54
54
|
class QueryNs < Blather::Stanza::Iq::Query; register :query_ns, nil, 'query:ns'; end
|
55
|
-
Blather::XMPPNode.class_from_registration(:query, 'query:ns').
|
55
|
+
Blather::XMPPNode.class_from_registration(:query, 'query:ns').should == QueryNs
|
56
56
|
query_ns = QueryNs.new
|
57
|
-
query_ns.xpath('query').
|
58
|
-
query_ns.xpath('ns:query', :ns => 'query:ns').size.
|
57
|
+
query_ns.xpath('query').should be_empty
|
58
|
+
query_ns.xpath('ns:query', :ns => 'query:ns').size.should == 1
|
59
59
|
|
60
60
|
query_ns.query
|
61
61
|
query_ns.query
|
62
|
-
query_ns.xpath('ns:query', :ns => 'query:ns').size.
|
62
|
+
query_ns.xpath('ns:query', :ns => 'query:ns').size.should == 1
|
63
63
|
end
|
64
64
|
end
|
@@ -26,40 +26,39 @@ end
|
|
26
26
|
|
27
27
|
describe Blather::Stanza::Iq::Roster do
|
28
28
|
it 'registers itself' do
|
29
|
-
Blather::XMPPNode.class_from_registration(:query, 'jabber:iq:roster').
|
29
|
+
Blather::XMPPNode.class_from_registration(:query, 'jabber:iq:roster').should == Blather::Stanza::Iq::Roster
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'ensures newly inherited items are RosterItem objects' do
|
33
33
|
n = parse_stanza roster_xml
|
34
34
|
r = Blather::Stanza::Iq::Roster.new.inherit n.root
|
35
|
-
r.items.map { |i| i.class }.uniq.
|
35
|
+
r.items.map { |i| i.class }.uniq.should == [Blather::Stanza::Iq::Roster::RosterItem]
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'can be created with #import' do
|
39
|
-
|
40
|
-
Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Iq::Roster
|
39
|
+
Blather::XMPPNode.parse(roster_xml).should be_instance_of Blather::Stanza::Iq::Roster
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
43
|
describe Blather::Stanza::Iq::Roster::RosterItem do
|
45
44
|
it 'can be initialized with just a Blather::JID' do
|
46
45
|
i = Blather::Stanza::Iq::Roster::RosterItem.new 'n@d/r'
|
47
|
-
i.jid.
|
46
|
+
i.jid.should == Blather::JID.new('n@d/r').stripped
|
48
47
|
end
|
49
48
|
|
50
49
|
it 'can be initialized with a name' do
|
51
50
|
i = Blather::Stanza::Iq::Roster::RosterItem.new nil, 'foobar'
|
52
|
-
i.name.
|
51
|
+
i.name.should == 'foobar'
|
53
52
|
end
|
54
53
|
|
55
54
|
it 'can be initialized with a subscription' do
|
56
55
|
i = Blather::Stanza::Iq::Roster::RosterItem.new nil, nil, :both
|
57
|
-
i.subscription.
|
56
|
+
i.subscription.should == :both
|
58
57
|
end
|
59
58
|
|
60
59
|
it 'can be initialized with ask (subscription sub-type)' do
|
61
60
|
i = Blather::Stanza::Iq::Roster::RosterItem.new nil, nil, nil, :subscribe
|
62
|
-
i.ask.
|
61
|
+
i.ask.should == :subscribe
|
63
62
|
end
|
64
63
|
|
65
64
|
it 'can be initailized with a hash' do
|
@@ -68,10 +67,10 @@ describe Blather::Stanza::Iq::Roster::RosterItem do
|
|
68
67
|
:subscription => :both,
|
69
68
|
:ask => :subscribe }
|
70
69
|
i = Blather::Stanza::Iq::Roster::RosterItem.new control
|
71
|
-
i.jid.
|
72
|
-
i.name.
|
73
|
-
i.subscription.
|
74
|
-
i.ask.
|
70
|
+
i.jid.should == Blather::JID.new(control[:jid]).stripped
|
71
|
+
i.name.should == control[:name]
|
72
|
+
i.subscription.should == control[:subscription]
|
73
|
+
i.ask.should == control[:ask]
|
75
74
|
end
|
76
75
|
|
77
76
|
it 'inherits a node when initialized with one' do
|
@@ -80,61 +79,61 @@ describe Blather::Stanza::Iq::Roster::RosterItem do
|
|
80
79
|
n[:subscription] = 'both'
|
81
80
|
|
82
81
|
i = Blather::Stanza::Iq::Roster::RosterItem.new n
|
83
|
-
i.jid.
|
84
|
-
i.subscription.
|
82
|
+
i.jid.should == Blather::JID.new('n@d/r')
|
83
|
+
i.subscription.should == :both
|
85
84
|
end
|
86
85
|
|
87
86
|
it 'has a #groups helper that gives an array of groups' do
|
88
87
|
n = parse_stanza "<item jid='romeo@example.net' subscription='both'><group>foo</group><group>bar</group><group>baz</group></item>"
|
89
88
|
i = Blather::Stanza::Iq::Roster::RosterItem.new n.root
|
90
|
-
i.
|
91
|
-
i.groups.sort.
|
89
|
+
i.should respond_to :groups
|
90
|
+
i.groups.sort.should == %w[bar baz foo]
|
92
91
|
end
|
93
92
|
|
94
93
|
it 'has a helper to set the groups' do
|
95
94
|
n = parse_stanza "<item jid='romeo@example.net' subscription='both'><group>foo</group><group>bar</group><group>baz</group></item>"
|
96
95
|
i = Blather::Stanza::Iq::Roster::RosterItem.new n.root
|
97
|
-
i.
|
98
|
-
i.groups.sort.
|
96
|
+
i.should respond_to :groups=
|
97
|
+
i.groups.sort.should == %w[bar baz foo]
|
99
98
|
i.groups = %w[a b c]
|
100
|
-
i.groups.sort.
|
99
|
+
i.groups.sort.should == %w[a b c]
|
101
100
|
end
|
102
101
|
|
103
102
|
it 'can be easily converted into a proper stanza' do
|
104
103
|
xml = "<item jid='romeo@example.net' subscription='both'><group>foo</group><group>bar</group><group>baz</group></item>"
|
105
104
|
n = parse_stanza xml
|
106
105
|
i = Blather::Stanza::Iq::Roster::RosterItem.new n.root
|
107
|
-
i.
|
106
|
+
i.should respond_to :to_stanza
|
108
107
|
s = i.to_stanza
|
109
|
-
s.
|
110
|
-
s.items.first.jid.
|
111
|
-
s.items.first.groups.sort.
|
108
|
+
s.should be_kind_of Blather::Stanza::Iq::Roster
|
109
|
+
s.items.first.jid.should == Blather::JID.new('romeo@example.net')
|
110
|
+
s.items.first.groups.sort.should == %w[bar baz foo]
|
112
111
|
end
|
113
112
|
|
114
113
|
it 'has an "attr_accessor" for jid' do
|
115
114
|
i = Blather::Stanza::Iq::Roster::RosterItem.new
|
116
|
-
i.
|
117
|
-
i.jid.
|
118
|
-
i.
|
115
|
+
i.should respond_to :jid
|
116
|
+
i.jid.should be_nil
|
117
|
+
i.should respond_to :jid=
|
119
118
|
i.jid = 'n@d/r'
|
120
|
-
i.jid.
|
119
|
+
i.jid.should == Blather::JID.new('n@d/r').stripped
|
121
120
|
end
|
122
121
|
|
123
122
|
it 'has a name attribute' do
|
124
123
|
i = Blather::Stanza::Iq::Roster::RosterItem.new
|
125
124
|
i.name = 'name'
|
126
|
-
i.name.
|
125
|
+
i.name.should == 'name'
|
127
126
|
end
|
128
127
|
|
129
128
|
it 'has a subscription attribute' do
|
130
129
|
i = Blather::Stanza::Iq::Roster::RosterItem.new
|
131
130
|
i.subscription = :both
|
132
|
-
i.subscription.
|
131
|
+
i.subscription.should == :both
|
133
132
|
end
|
134
133
|
|
135
134
|
it 'has an ask attribute' do
|
136
135
|
i = Blather::Stanza::Iq::Roster::RosterItem.new
|
137
136
|
i.ask = :subscribe
|
138
|
-
i.ask.
|
137
|
+
i.ask.should == :subscribe
|
139
138
|
end
|
140
139
|
end
|
@@ -23,38 +23,35 @@ end
|
|
23
23
|
|
24
24
|
describe Blather::Stanza::Iq::S5b do
|
25
25
|
it 'registers itself' do
|
26
|
-
Blather::XMPPNode.class_from_registration(:query, 'http://jabber.org/protocol/bytestreams').
|
26
|
+
Blather::XMPPNode.class_from_registration(:query, 'http://jabber.org/protocol/bytestreams').should == Blather::Stanza::Iq::S5b
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'can be imported' do
|
30
|
-
|
31
|
-
node
|
32
|
-
node.must_be_instance_of Blather::Stanza::Iq::S5b
|
30
|
+
node = Blather::XMPPNode.parse s5b_open_xml
|
31
|
+
node.should be_instance_of Blather::Stanza::Iq::S5b
|
33
32
|
end
|
34
33
|
|
35
34
|
it 'can get sid' do
|
36
|
-
|
37
|
-
node
|
38
|
-
node.sid.must_equal 'vxf9n471bn46'
|
35
|
+
node = Blather::XMPPNode.parse s5b_open_xml
|
36
|
+
node.sid.should == 'vxf9n471bn46'
|
39
37
|
end
|
40
38
|
|
41
39
|
it 'can get streamhosts' do
|
42
|
-
|
43
|
-
node
|
44
|
-
node.streamhosts.size.must_equal 2
|
40
|
+
node = Blather::XMPPNode.parse s5b_open_xml
|
41
|
+
node.streamhosts.size.should == 2
|
45
42
|
end
|
46
43
|
|
47
44
|
it 'can set streamhosts' do
|
48
45
|
node = Blather::Stanza::Iq::S5b.new
|
49
46
|
node.streamhosts += [{:jid => 'test@example.com/foo', :host => '192.168.5.1', :port => 123}]
|
50
|
-
node.streamhosts.size.
|
47
|
+
node.streamhosts.size.should == 1
|
51
48
|
node.streamhosts += [Blather::Stanza::Iq::S5b::StreamHost.new('test2@example.com/foo', '192.168.5.2', 123)]
|
52
|
-
node.streamhosts.size.
|
49
|
+
node.streamhosts.size.should == 2
|
53
50
|
end
|
54
51
|
|
55
52
|
it 'can get and set streamhost-used' do
|
56
53
|
node = Blather::Stanza::Iq::S5b.new
|
57
54
|
node.streamhost_used = 'used@example.com/foo'
|
58
|
-
node.streamhost_used.jid.to_s.
|
55
|
+
node.streamhost_used.jid.to_s.should == 'used@example.com/foo'
|
59
56
|
end
|
60
57
|
end
|
@@ -27,41 +27,39 @@ end
|
|
27
27
|
|
28
28
|
describe Blather::Stanza::Iq::Si do
|
29
29
|
it 'registers itself' do
|
30
|
-
Blather::XMPPNode.class_from_registration(:si, 'http://jabber.org/protocol/si').
|
30
|
+
Blather::XMPPNode.class_from_registration(:si, 'http://jabber.org/protocol/si').should == Blather::Stanza::Iq::Si
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'can be imported' do
|
34
|
-
|
35
|
-
node
|
36
|
-
node.
|
37
|
-
node.si.must_be_instance_of Blather::Stanza::Iq::Si::Si
|
34
|
+
node = Blather::XMPPNode.parse si_xml
|
35
|
+
node.should be_instance_of Blather::Stanza::Iq::Si
|
36
|
+
node.si.should be_instance_of Blather::Stanza::Iq::Si::Si
|
38
37
|
end
|
39
38
|
|
40
39
|
it 'ensures a si node is present on create' do
|
41
40
|
iq = Blather::Stanza::Iq::Si.new
|
42
|
-
iq.xpath('ns:si', :ns => 'http://jabber.org/protocol/si').
|
41
|
+
iq.xpath('ns:si', :ns => 'http://jabber.org/protocol/si').should_not be_empty
|
43
42
|
end
|
44
43
|
|
45
44
|
it 'ensures a si node exists when calling #si' do
|
46
45
|
iq = Blather::Stanza::Iq::Si.new
|
47
46
|
iq.si.remove
|
48
|
-
iq.xpath('ns:si', :ns => 'http://jabber.org/protocol/si').
|
47
|
+
iq.xpath('ns:si', :ns => 'http://jabber.org/protocol/si').should be_empty
|
49
48
|
|
50
|
-
iq.si.
|
51
|
-
iq.xpath('ns:si', :ns => 'http://jabber.org/protocol/si').
|
49
|
+
iq.si.should_not be_nil
|
50
|
+
iq.xpath('ns:si', :ns => 'http://jabber.org/protocol/si').should_not be_empty
|
52
51
|
end
|
53
52
|
|
54
53
|
it 'ensures a si node is replaced when calling #si=' do
|
55
|
-
|
56
|
-
iq = Blather::XMPPNode.import(doc.root)
|
54
|
+
iq = Blather::XMPPNode.parse si_xml
|
57
55
|
|
58
56
|
new_si = Blather::Stanza::Iq::Si::Si.new
|
59
57
|
new_si.id = 'a1'
|
60
58
|
|
61
59
|
iq.si = new_si
|
62
60
|
|
63
|
-
iq.xpath('ns:si', :ns => 'http://jabber.org/protocol/si').size.
|
64
|
-
iq.si.id.
|
61
|
+
iq.xpath('ns:si', :ns => 'http://jabber.org/protocol/si').size.should == 1
|
62
|
+
iq.si.id.should == 'a1'
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
@@ -71,31 +69,30 @@ describe Blather::Stanza::Iq::Si::Si do
|
|
71
69
|
si.id = 'a1'
|
72
70
|
si.mime_type = 'text/plain'
|
73
71
|
si.profile = 'http://jabber.org/protocol/si/profile/file-transfer'
|
74
|
-
si.id.
|
75
|
-
si.mime_type.
|
76
|
-
si.profile.
|
72
|
+
si.id.should == 'a1'
|
73
|
+
si.mime_type.should == 'text/plain'
|
74
|
+
si.profile.should == 'http://jabber.org/protocol/si/profile/file-transfer'
|
77
75
|
end
|
78
76
|
end
|
79
77
|
|
80
78
|
describe Blather::Stanza::Iq::Si::Si::File do
|
81
79
|
it 'can be initialized with name and size' do
|
82
80
|
file = Blather::Stanza::Iq::Si::Si::File.new('test.txt', 123)
|
83
|
-
file.name.
|
84
|
-
file.size.
|
81
|
+
file.name.should == 'test.txt'
|
82
|
+
file.size.should == 123
|
85
83
|
end
|
86
84
|
|
87
85
|
it 'can be initialized with node' do
|
88
|
-
|
89
|
-
node = Blather::XMPPNode.import(doc.root)
|
86
|
+
node = Blather::XMPPNode.parse si_xml
|
90
87
|
|
91
88
|
file = Blather::Stanza::Iq::Si::Si::File.new node.find_first('.//ns:file', :ns => 'http://jabber.org/protocol/si/profile/file-transfer')
|
92
|
-
file.name.
|
93
|
-
file.size.
|
89
|
+
file.name.should == 'test.txt'
|
90
|
+
file.size.should == 1022
|
94
91
|
end
|
95
92
|
|
96
93
|
it 'can set and get description' do
|
97
94
|
file = Blather::Stanza::Iq::Si::Si::File.new('test.txt', 123)
|
98
95
|
file.desc = 'This is a test. If this were a real file...'
|
99
|
-
file.desc.
|
96
|
+
file.desc.should == 'This is a test. If this were a real file...'
|
100
97
|
end
|
101
98
|
end
|
@@ -12,41 +12,39 @@ end
|
|
12
12
|
|
13
13
|
describe Blather::Stanza::Iq::Vcard do
|
14
14
|
it 'registers itself' do
|
15
|
-
Blather::XMPPNode.class_from_registration(:vCard, 'vcard-temp').
|
15
|
+
Blather::XMPPNode.class_from_registration(:vCard, 'vcard-temp').should == Blather::Stanza::Iq::Vcard
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'can be imported' do
|
19
|
-
|
20
|
-
query
|
21
|
-
query.
|
22
|
-
query.vcard.must_be_instance_of Blather::Stanza::Iq::Vcard::Vcard
|
19
|
+
query = Blather::XMPPNode.parse vcard_xml
|
20
|
+
query.should be_instance_of Blather::Stanza::Iq::Vcard
|
21
|
+
query.vcard.should be_instance_of Blather::Stanza::Iq::Vcard::Vcard
|
23
22
|
end
|
24
23
|
|
25
24
|
it 'ensures a vcard node is present on create' do
|
26
25
|
query = Blather::Stanza::Iq::Vcard.new
|
27
|
-
query.xpath('ns:vCard', :ns => 'vcard-temp').
|
26
|
+
query.xpath('ns:vCard', :ns => 'vcard-temp').should_not be_empty
|
28
27
|
end
|
29
28
|
|
30
29
|
it 'ensures a vcard node exists when calling #vcard' do
|
31
30
|
query = Blather::Stanza::Iq::Vcard.new
|
32
31
|
query.vcard.remove
|
33
|
-
query.xpath('ns:vCard', :ns => 'vcard-temp').
|
32
|
+
query.xpath('ns:vCard', :ns => 'vcard-temp').should be_empty
|
34
33
|
|
35
|
-
query.vcard.
|
36
|
-
query.xpath('ns:vCard', :ns => 'vcard-temp').
|
34
|
+
query.vcard.should_not be_nil
|
35
|
+
query.xpath('ns:vCard', :ns => 'vcard-temp').should_not be_empty
|
37
36
|
end
|
38
37
|
|
39
38
|
it 'ensures a vcard node is replaced when calling #vcard=' do
|
40
|
-
|
41
|
-
query = Blather::XMPPNode.import(doc.root)
|
39
|
+
query = Blather::XMPPNode.parse vcard_xml
|
42
40
|
|
43
41
|
new_vcard = Blather::Stanza::Iq::Vcard::Vcard.new
|
44
42
|
new_vcard["NICKNAME"] = 'Mercutio'
|
45
43
|
|
46
44
|
query.vcard = new_vcard
|
47
45
|
|
48
|
-
query.xpath('ns:vCard', :ns => 'vcard-temp').size.
|
49
|
-
query.find_first('ns:vCard/ns:NICKNAME', :ns => 'vcard-temp').content.
|
46
|
+
query.xpath('ns:vCard', :ns => 'vcard-temp').size.should == 1
|
47
|
+
query.find_first('ns:vCard/ns:NICKNAME', :ns => 'vcard-temp').content.should == 'Mercutio'
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
@@ -54,43 +52,42 @@ describe Blather::Stanza::Iq::Vcard::Vcard do
|
|
54
52
|
it 'can set vcard elements' do
|
55
53
|
query = Blather::Stanza::Iq::Vcard.new :set
|
56
54
|
query.vcard['NICKNAME'] = 'Romeo'
|
57
|
-
query.find_first('ns:vCard/ns:NICKNAME', :ns => 'vcard-temp').content.
|
55
|
+
query.find_first('ns:vCard/ns:NICKNAME', :ns => 'vcard-temp').content.should == 'Romeo'
|
58
56
|
end
|
59
57
|
|
60
58
|
it 'can set deep vcard elements' do
|
61
59
|
query = Blather::Stanza::Iq::Vcard.new :set
|
62
60
|
query.vcard['PHOTO/TYPE'] = 'image/png'
|
63
61
|
query.vcard['PHOTO/BINVAL'] = '===='
|
64
|
-
query.find_first('ns:vCard/ns:PHOTO', :ns => 'vcard-temp').children.size.
|
65
|
-
query.find_first('ns:vCard/ns:PHOTO', :ns => 'vcard-temp').children.detect { |n| n.element_name == 'TYPE' && n.content == 'image/png' }.
|
66
|
-
query.find_first('ns:vCard/ns:PHOTO', :ns => 'vcard-temp').children.detect { |n| n.element_name == 'BINVAL' && n.content == '====' }.
|
62
|
+
query.find_first('ns:vCard/ns:PHOTO', :ns => 'vcard-temp').children.size.should == 2
|
63
|
+
query.find_first('ns:vCard/ns:PHOTO', :ns => 'vcard-temp').children.detect { |n| n.element_name == 'TYPE' && n.content == 'image/png' }.should_not be_nil
|
64
|
+
query.find_first('ns:vCard/ns:PHOTO', :ns => 'vcard-temp').children.detect { |n| n.element_name == 'BINVAL' && n.content == '====' }.should_not be_nil
|
67
65
|
end
|
68
66
|
|
69
67
|
it 'can get vcard elements' do
|
70
68
|
query = Blather::Stanza::Iq::Vcard.new :set
|
71
69
|
query.vcard['NICKNAME'] = 'Romeo'
|
72
|
-
query.vcard['NICKNAME'].
|
70
|
+
query.vcard['NICKNAME'].should == 'Romeo'
|
73
71
|
end
|
74
72
|
|
75
73
|
it 'can get deep vcard elements' do
|
76
74
|
query = Blather::Stanza::Iq::Vcard.new :set
|
77
75
|
query.vcard['PHOTO/TYPE'] = 'image/png'
|
78
76
|
query.vcard['PHOTO/BINVAL'] = '===='
|
79
|
-
query.vcard['PHOTO/TYPE'].
|
80
|
-
query.vcard['PHOTO/BINVAL'].
|
77
|
+
query.vcard['PHOTO/TYPE'].should == 'image/png'
|
78
|
+
query.vcard['PHOTO/BINVAL'].should == '===='
|
81
79
|
end
|
82
80
|
|
83
81
|
it 'returns nil on vcard elements which does not exist' do
|
84
82
|
query = Blather::Stanza::Iq::Vcard.new :set
|
85
83
|
query.vcard['NICKNAME'] = 'Romeo'
|
86
|
-
query.vcard['FN'].
|
84
|
+
query.vcard['FN'].should be_nil
|
87
85
|
end
|
88
86
|
|
89
87
|
it 'can update vcard elements' do
|
90
|
-
|
91
|
-
query
|
92
|
-
query.vcard['NICKNAME'].must_equal 'Romeo'
|
88
|
+
query = Blather::XMPPNode.parse vcard_xml
|
89
|
+
query.vcard['NICKNAME'].should == 'Romeo'
|
93
90
|
query.vcard['NICKNAME'] = 'Mercutio'
|
94
|
-
query.vcard['NICKNAME'].
|
91
|
+
query.vcard['NICKNAME'].should == 'Mercutio'
|
95
92
|
end
|
96
93
|
end
|