blather 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +41 -12
- data/examples/echo.rb +1 -1
- data/examples/execute.rb +0 -5
- data/examples/pubsub/cli.rb +64 -0
- data/examples/pubsub/ping_pong.rb +18 -0
- data/examples/rosterprint.rb +14 -0
- data/examples/xmpp4r/echo.rb +35 -0
- data/lib/blather.rb +35 -12
- data/lib/blather/client.rb +1 -1
- data/lib/blather/client/client.rb +19 -13
- data/lib/blather/client/dsl.rb +16 -0
- data/lib/blather/client/dsl/pubsub.rb +133 -0
- data/lib/blather/core_ext/active_support.rb +1 -117
- data/lib/blather/core_ext/active_support/inheritable_attributes.rb +117 -0
- data/lib/blather/core_ext/nokogiri.rb +35 -0
- data/lib/blather/errors.rb +3 -20
- data/lib/blather/errors/sasl_error.rb +3 -1
- data/lib/blather/errors/stanza_error.rb +10 -17
- data/lib/blather/errors/stream_error.rb +11 -14
- data/lib/blather/jid.rb +1 -0
- data/lib/blather/roster.rb +9 -0
- data/lib/blather/roster_item.rb +6 -1
- data/lib/blather/stanza.rb +35 -18
- data/lib/blather/stanza/disco.rb +7 -1
- data/lib/blather/stanza/disco/disco_info.rb +45 -33
- data/lib/blather/stanza/disco/disco_items.rb +32 -21
- data/lib/blather/stanza/iq.rb +13 -8
- data/lib/blather/stanza/iq/query.rb +16 -8
- data/lib/blather/stanza/iq/roster.rb +33 -22
- data/lib/blather/stanza/message.rb +20 -31
- data/lib/blather/stanza/presence.rb +3 -5
- data/lib/blather/stanza/presence/status.rb +13 -21
- data/lib/blather/stanza/presence/subscription.rb +11 -16
- data/lib/blather/stanza/pubsub.rb +63 -0
- data/lib/blather/stanza/pubsub/affiliations.rb +50 -0
- data/lib/blather/stanza/pubsub/create.rb +43 -0
- data/lib/blather/stanza/pubsub/errors.rb +9 -0
- data/lib/blather/stanza/pubsub/event.rb +77 -0
- data/lib/blather/stanza/pubsub/items.rb +63 -0
- data/lib/blather/stanza/pubsub/publish.rb +58 -0
- data/lib/blather/stanza/pubsub/retract.rb +53 -0
- data/lib/blather/stanza/pubsub/subscribe.rb +42 -0
- data/lib/blather/stanza/pubsub/subscription.rb +66 -0
- data/lib/blather/stanza/pubsub/subscriptions.rb +55 -0
- data/lib/blather/stanza/pubsub/unsubscribe.rb +42 -0
- data/lib/blather/stanza/pubsub_owner.rb +41 -0
- data/lib/blather/stanza/pubsub_owner/delete.rb +34 -0
- data/lib/blather/stanza/pubsub_owner/purge.rb +34 -0
- data/lib/blather/stream.rb +76 -168
- data/lib/blather/stream/client.rb +1 -2
- data/lib/blather/stream/component.rb +9 -5
- data/lib/blather/stream/features.rb +53 -0
- data/lib/blather/stream/features/resource.rb +63 -0
- data/lib/blather/stream/{sasl.rb → features/sasl.rb} +53 -52
- data/lib/blather/stream/features/session.rb +44 -0
- data/lib/blather/stream/features/tls.rb +28 -0
- data/lib/blather/stream/parser.rb +70 -46
- data/lib/blather/xmpp_node.rb +113 -52
- data/spec/blather/client/client_spec.rb +44 -58
- data/spec/blather/client/dsl/pubsub_spec.rb +465 -0
- data/spec/blather/client/dsl_spec.rb +19 -6
- data/spec/blather/core_ext/nokogiri_spec.rb +83 -0
- data/spec/blather/errors/sasl_error_spec.rb +8 -8
- data/spec/blather/errors/stanza_error_spec.rb +25 -33
- data/spec/blather/errors/stream_error_spec.rb +21 -16
- data/spec/blather/errors_spec.rb +4 -11
- data/spec/blather/jid_spec.rb +31 -30
- data/spec/blather/roster_item_spec.rb +34 -23
- data/spec/blather/roster_spec.rb +27 -12
- data/spec/blather/stanza/discos/disco_info_spec.rb +61 -42
- data/spec/blather/stanza/discos/disco_items_spec.rb +47 -35
- data/spec/blather/stanza/iq/query_spec.rb +34 -11
- data/spec/blather/stanza/iq/roster_spec.rb +47 -30
- data/spec/blather/stanza/iq_spec.rb +19 -14
- data/spec/blather/stanza/message_spec.rb +30 -17
- data/spec/blather/stanza/presence/status_spec.rb +43 -20
- data/spec/blather/stanza/presence/subscription_spec.rb +41 -21
- data/spec/blather/stanza/presence_spec.rb +34 -21
- data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
- data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
- data/spec/blather/stanza/pubsub/event_spec.rb +84 -0
- data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
- data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
- data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
- data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
- data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
- data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
- data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +61 -0
- data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
- data/spec/blather/stanza/pubsub_spec.rb +62 -0
- data/spec/blather/stanza_spec.rb +53 -38
- data/spec/blather/stream/client_spec.rb +231 -88
- data/spec/blather/stream/component_spec.rb +14 -5
- data/spec/blather/stream/parser_spec.rb +145 -0
- data/spec/blather/xmpp_node_spec.rb +192 -96
- data/spec/fixtures/pubsub.rb +311 -0
- data/spec/spec_helper.rb +5 -4
- metadata +54 -18
- data/Rakefile +0 -139
- data/ext/extconf.rb +0 -65
- data/ext/push_parser.c +0 -209
- data/lib/blather/core_ext/libxml.rb +0 -28
- data/lib/blather/stream/resource.rb +0 -48
- data/lib/blather/stream/session.rb +0 -36
- data/lib/blather/stream/stream_handler.rb +0 -39
- data/lib/blather/stream/tls.rb +0 -33
- data/spec/blather/core_ext/libxml_spec.rb +0 -58
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
2
2
|
require 'blather/client/dsl'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Blather::DSL do
|
5
5
|
before do
|
6
6
|
@client = mock()
|
7
|
-
@dsl =
|
8
|
-
Client.stubs(:new).returns(@client)
|
7
|
+
@dsl = Class.new { include Blather::DSL }.new
|
8
|
+
Blather::Client.stubs(:new).returns(@client)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'wraps the setup' do
|
@@ -55,6 +55,12 @@ describe 'Blather::DSL' do
|
|
55
55
|
@dsl.my_roster
|
56
56
|
end
|
57
57
|
|
58
|
+
it 'provides a << style writer that provides chaining' do
|
59
|
+
stanza = Blather::Stanza::Iq.new
|
60
|
+
@client.expects(:write).with stanza
|
61
|
+
(@dsl << stanza).must_equal @dsl
|
62
|
+
end
|
63
|
+
|
58
64
|
it 'provides a writer' do
|
59
65
|
stanza = Blather::Stanza::Iq.new
|
60
66
|
@client.expects(:write).with stanza
|
@@ -64,7 +70,7 @@ describe 'Blather::DSL' do
|
|
64
70
|
it 'provides a "say" helper' do
|
65
71
|
to, msg = 'me@me.com', 'hello!'
|
66
72
|
Blather::Stanza::Message.stubs(:next_id).returns 0
|
67
|
-
@client.expects(:write).with Blather::Stanza::Message.new(to, msg)
|
73
|
+
@client.expects(:write).with { |n| n.to_s.must_equal Blather::Stanza::Message.new(to, msg).to_s }
|
68
74
|
@dsl.say to, msg
|
69
75
|
end
|
70
76
|
|
@@ -80,7 +86,7 @@ describe 'Blather::DSL' do
|
|
80
86
|
expected_stanza = Blather::Stanza::Disco::DiscoItems.new
|
81
87
|
expected_stanza.to = who
|
82
88
|
expected_stanza.node = where
|
83
|
-
@client.expects(:write).with expected_stanza
|
89
|
+
@client.expects(:write).with { |n| n.to_s.must_equal expected_stanza.to_s }
|
84
90
|
@dsl.discover what, who, where
|
85
91
|
end
|
86
92
|
|
@@ -91,7 +97,7 @@ describe 'Blather::DSL' do
|
|
91
97
|
expected_stanza = Blather::Stanza::Disco::DiscoInfo.new
|
92
98
|
expected_stanza.to = who
|
93
99
|
expected_stanza.node = where
|
94
|
-
@client.expects(:write).with expected_stanza
|
100
|
+
@client.expects(:write).with { |n| n.to_s.must_equal expected_stanza.to_s }
|
95
101
|
@dsl.discover what, who, where
|
96
102
|
end
|
97
103
|
|
@@ -102,4 +108,11 @@ describe 'Blather::DSL' do
|
|
102
108
|
@dsl.__send__(handler_method, *guards)
|
103
109
|
end
|
104
110
|
end
|
111
|
+
|
112
|
+
it 'has a pubsub helper set to the jid domain' do
|
113
|
+
jid = Blather::JID.new('jid@domain/resource')
|
114
|
+
@client.stubs(:jid).returns jid
|
115
|
+
@dsl.pubsub.must_be_instance_of Blather::DSL::PubSub
|
116
|
+
@dsl.pubsub.host.must_equal jid.domain
|
117
|
+
end
|
105
118
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
2
|
+
|
3
|
+
describe 'Nokogiri::XML::Node' do
|
4
|
+
before { @doc = Nokogiri::XML::Document.new }
|
5
|
+
|
6
|
+
it 'aliases #name to #element_name' do
|
7
|
+
node = Nokogiri::XML::Node.new 'foo', @doc
|
8
|
+
node.must_respond_to :element_name
|
9
|
+
node.element_name.must_equal node.name
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'aliases #name= to #element_name=' do
|
13
|
+
node = Nokogiri::XML::Node.new 'foo', @doc
|
14
|
+
node.must_respond_to :element_name=
|
15
|
+
node.element_name.must_equal node.name
|
16
|
+
node.element_name = 'bar'
|
17
|
+
node.element_name.must_equal 'bar'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'allows symbols as hash keys for attributes' do
|
21
|
+
attrs = Nokogiri::XML::Node.new('foo', @doc)
|
22
|
+
attrs['foo'] = 'bar'
|
23
|
+
|
24
|
+
attrs['foo'].must_equal 'bar'
|
25
|
+
attrs[:foo].must_equal 'bar'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'ensures a string is passed to the attribute setter' do
|
29
|
+
attrs = Nokogiri::XML::Node.new('foo', @doc)
|
30
|
+
attrs[:foo] = 1
|
31
|
+
attrs[:foo].must_equal '1'
|
32
|
+
|
33
|
+
attrs[:jid] = Blather::JID.new('n@d/r')
|
34
|
+
attrs[:jid].must_equal 'n@d/r'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'removes an attribute when set to nil' do
|
38
|
+
attrs = Nokogiri::XML::Node.new('foo', @doc)
|
39
|
+
attrs['foo'] = 'bar'
|
40
|
+
|
41
|
+
attrs['foo'].must_equal 'bar'
|
42
|
+
attrs['foo'] = nil
|
43
|
+
attrs['foo'].must_be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'allows attribute values to change' do
|
47
|
+
attrs = Nokogiri::XML::Node.new('foo', @doc)
|
48
|
+
attrs['foo'] = 'bar'
|
49
|
+
|
50
|
+
attrs['foo'].must_equal 'bar'
|
51
|
+
attrs['foo'] = 'baz'
|
52
|
+
attrs['foo'].must_equal 'baz'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'allows symbols as the path in #xpath' do
|
56
|
+
node = Nokogiri::XML::Node.new('foo', @doc)
|
57
|
+
node.must_respond_to :find
|
58
|
+
@doc.root = node
|
59
|
+
@doc.xpath(:foo).first.wont_be_nil
|
60
|
+
@doc.xpath(:foo).first.must_equal @doc.xpath('/foo').first
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'allows symbols as namespace names in #xpath' do
|
64
|
+
node = Nokogiri::XML::Node.new('foo', @doc)
|
65
|
+
node.namespace = node.add_namespace('bar', 'baz')
|
66
|
+
@doc.root = node
|
67
|
+
node.xpath('/bar:foo', :bar => 'baz').first.wont_be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'aliases #xpath to #find' do
|
71
|
+
node = Nokogiri::XML::Node.new('foo', @doc)
|
72
|
+
node.must_respond_to :find
|
73
|
+
@doc.root = node
|
74
|
+
node.find('/foo').first.wont_be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'has a helper function #find_first' do
|
78
|
+
node = Nokogiri::XML::Node.new('foo', @doc)
|
79
|
+
node.must_respond_to :find
|
80
|
+
@doc.root = node
|
81
|
+
node.find_first('/foo').must_equal node.find('/foo').first
|
82
|
+
end
|
83
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
2
2
|
|
3
3
|
def sasl_error_node(err_name = 'aborted')
|
4
|
-
node = XMPPNode.new 'failure'
|
5
|
-
node.namespace =
|
4
|
+
node = Blather::XMPPNode.new 'failure'
|
5
|
+
node.namespace = Blather::SASLError::SASL_ERR_NS
|
6
6
|
|
7
|
-
node << XMPPNode.new(err_name)
|
7
|
+
node << Blather::XMPPNode.new(err_name, node.document)
|
8
8
|
node
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe Blather::SASLError do
|
12
12
|
it 'can import a node' do
|
13
|
-
SASLError.must_respond_to :import
|
14
|
-
e = SASLError.import sasl_error_node
|
15
|
-
e.must_be_kind_of SASLError
|
13
|
+
Blather::SASLError.must_respond_to :import
|
14
|
+
e = Blather::SASLError.import sasl_error_node
|
15
|
+
e.must_be_kind_of Blather::SASLError
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'each XMPP SASL error type' do
|
@@ -25,7 +25,7 @@ describe 'Blather::SASLError' do
|
|
25
25
|
temporary-auth-failure
|
26
26
|
].each do |error_type|
|
27
27
|
it "handles the name for #{error_type}" do
|
28
|
-
e = SASLError.import sasl_error_node(error_type)
|
28
|
+
e = Blather::SASLError.import sasl_error_node(error_type)
|
29
29
|
e.name.must_equal error_type.gsub('-','_').to_sym
|
30
30
|
end
|
31
31
|
end
|
@@ -1,47 +1,42 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
2
2
|
|
3
3
|
def stanza_error_node(type = 'cancel', error = 'internal-server-error', msg = nil)
|
4
|
-
node = Stanza::Message.new 'error@jabber.local', 'test message', :error
|
5
|
-
XML::Document.new.root = node
|
4
|
+
node = Blather::Stanza::Message.new 'error@jabber.local', 'test message', :error
|
6
5
|
|
7
|
-
error_node = XMPPNode.new('error')
|
6
|
+
node << (error_node = Blather::XMPPNode.new('error'))
|
8
7
|
error_node['type'] = type.to_s
|
9
8
|
|
10
|
-
err = XMPPNode.new(error)
|
9
|
+
error_node << (err = Blather::XMPPNode.new(error, error_node.document))
|
11
10
|
err.namespace = 'urn:ietf:params:xml:ns:xmpp-stanzas'
|
12
|
-
error_node << err
|
13
11
|
|
14
12
|
if msg
|
15
|
-
text = XMPPNode.new('text')
|
13
|
+
error_node << (text = Blather::XMPPNode.new('text', error_node.document))
|
16
14
|
text.namespace = 'urn:ietf:params:xml:ns:xmpp-stanzas'
|
17
|
-
text
|
18
|
-
error_node << text
|
15
|
+
text.content = msg
|
19
16
|
end
|
20
17
|
|
21
|
-
extra = XMPPNode.new('extra-error')
|
18
|
+
error_node << (extra = Blather::XMPPNode.new('extra-error', error_node.document))
|
22
19
|
extra.namespace = 'blather:stanza:error'
|
23
|
-
extra
|
24
|
-
error_node << extra
|
20
|
+
extra.content = 'Blather Error'
|
25
21
|
|
26
|
-
node << error_node
|
27
22
|
node
|
28
23
|
end
|
29
24
|
|
30
|
-
describe
|
25
|
+
describe Blather::StanzaError do
|
31
26
|
it 'can import a node' do
|
32
|
-
StanzaError.must_respond_to :import
|
33
|
-
e = StanzaError.import stanza_error_node
|
34
|
-
e.must_be_kind_of StanzaError
|
27
|
+
Blather::StanzaError.must_respond_to :import
|
28
|
+
e = Blather::StanzaError.import stanza_error_node
|
29
|
+
e.must_be_kind_of Blather::StanzaError
|
35
30
|
end
|
36
31
|
|
37
32
|
describe 'valid types' do
|
38
|
-
before { @original = Stanza::Message.new 'error@jabber.local', 'test message', :error }
|
33
|
+
before { @original = Blather::Stanza::Message.new 'error@jabber.local', 'test message', :error }
|
39
34
|
|
40
35
|
it 'ensures type is one of Stanza::Message::VALID_TYPES' do
|
41
|
-
lambda { StanzaError.new @original, :gone, :invalid_type_name }.must_raise(Blather::ArgumentError)
|
36
|
+
lambda { Blather::StanzaError.new @original, :gone, :invalid_type_name }.must_raise(Blather::ArgumentError)
|
42
37
|
|
43
|
-
StanzaError::VALID_TYPES.each do |valid_type|
|
44
|
-
msg = StanzaError.new @original, :gone, valid_type
|
38
|
+
Blather::StanzaError::VALID_TYPES.each do |valid_type|
|
39
|
+
msg = Blather::StanzaError.new @original, :gone, valid_type
|
45
40
|
msg.type.must_equal valid_type
|
46
41
|
end
|
47
42
|
end
|
@@ -52,7 +47,7 @@ describe 'Blather::StanzaError' do
|
|
52
47
|
@type = 'cancel'
|
53
48
|
@err_name = 'internal-server-error'
|
54
49
|
@msg = 'the server has experienced a misconfiguration'
|
55
|
-
@err = StanzaError.import stanza_error_node(@type, @err_name, @msg)
|
50
|
+
@err = Blather::StanzaError.import stanza_error_node(@type, @err_name, @msg)
|
56
51
|
end
|
57
52
|
|
58
53
|
it 'provides a type attribute' do
|
@@ -72,7 +67,7 @@ describe 'Blather::StanzaError' do
|
|
72
67
|
|
73
68
|
it 'provides a reader to the original node' do
|
74
69
|
@err.must_respond_to :original
|
75
|
-
@err.original.must_be_instance_of Stanza::Message
|
70
|
+
@err.original.must_be_instance_of Blather::Stanza::Message
|
76
71
|
end
|
77
72
|
|
78
73
|
it 'provides an extras attribute' do
|
@@ -91,14 +86,13 @@ describe 'Blather::StanzaError' do
|
|
91
86
|
|
92
87
|
it 'can be turned into xml' do
|
93
88
|
@err.must_respond_to :to_xml
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
test_msg.must_match(/<message[^>]*type="error"/)
|
89
|
+
doc = parse_stanza @err.to_xml
|
90
|
+
|
91
|
+
doc.xpath("/message[@from='error@jabber.local' and @type='error']").wont_be_empty
|
92
|
+
doc.xpath("/message/error").wont_be_empty
|
93
|
+
doc.xpath("/message/error/err_ns:internal-server-error", :err_ns => Blather::StanzaError::STANZA_ERR_NS).wont_be_empty
|
94
|
+
doc.xpath("/message/error/err_ns:text[.='the server has experienced a misconfiguration']", :err_ns => Blather::StanzaError::STANZA_ERR_NS).wont_be_empty
|
95
|
+
doc.xpath("/message/error/extra_ns:extra-error[.='Blather Error']", :extra_ns => 'blather:stanza:error').wont_be_empty
|
102
96
|
end
|
103
97
|
end
|
104
98
|
|
@@ -127,11 +121,9 @@ describe 'Blather::StanzaError' do
|
|
127
121
|
unexpected-request
|
128
122
|
].each do |error_type|
|
129
123
|
it "handles the name for #{error_type}" do
|
130
|
-
e = StanzaError.import stanza_error_node(:cancel, error_type)
|
124
|
+
e = Blather::StanzaError.import stanza_error_node(:cancel, error_type)
|
131
125
|
e.name.must_equal error_type.gsub('-','_').to_sym
|
132
126
|
end
|
133
127
|
end
|
134
128
|
end
|
135
129
|
end
|
136
|
-
|
137
|
-
|
@@ -1,33 +1,35 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
2
2
|
|
3
3
|
def stream_error_node(error = 'internal-server-error', msg = nil)
|
4
|
-
node = XMPPNode.new('
|
5
|
-
|
4
|
+
node = Blather::XMPPNode.new('error')
|
5
|
+
node.namespace = {'stream' => Blather::Stream::STREAM_NS}
|
6
6
|
|
7
|
-
err = XMPPNode.new(error)
|
7
|
+
node << (err = Blather::XMPPNode.new(error, node.document))
|
8
8
|
err.namespace = 'urn:ietf:params:xml:ns:xmpp-streams'
|
9
|
-
node << err
|
10
9
|
|
11
10
|
if msg
|
12
|
-
text = XMPPNode.new('text')
|
11
|
+
node << (text = Blather::XMPPNode.new('text', node.document))
|
13
12
|
text.namespace = 'urn:ietf:params:xml:ns:xmpp-streams'
|
14
|
-
text
|
15
|
-
node << text
|
13
|
+
text.content = msg
|
16
14
|
end
|
17
15
|
|
18
|
-
extra = XMPPNode.new('extra-error')
|
16
|
+
node << (extra = Blather::XMPPNode.new('extra-error', node.document))
|
19
17
|
extra.namespace = 'blather:stream:error'
|
20
|
-
extra
|
18
|
+
extra.content = 'Blather Error'
|
21
19
|
|
22
|
-
node << extra
|
23
20
|
node
|
24
21
|
end
|
25
22
|
|
26
23
|
describe 'Blather::StreamError' do
|
27
24
|
it 'can import a node' do
|
28
|
-
|
29
|
-
|
30
|
-
e.
|
25
|
+
err = stream_error_node 'internal-server-error', 'the message'
|
26
|
+
Blather::StreamError.must_respond_to :import
|
27
|
+
e = Blather::StreamError.import err
|
28
|
+
e.must_be_kind_of Blather::StreamError
|
29
|
+
|
30
|
+
e.name.must_equal :internal_server_error
|
31
|
+
e.text.must_equal 'the message'
|
32
|
+
e.extras.must_equal err.find('descendant::*[name()="extra-error"]', 'blather:stream:error').map {|n|n}
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -35,7 +37,7 @@ describe 'Blather::StreamError when instantiated' do
|
|
35
37
|
before do
|
36
38
|
@err_name = 'internal-server-error'
|
37
39
|
@msg = 'the server has experienced a misconfiguration'
|
38
|
-
@err = StreamError.import stream_error_node(@err_name, @msg)
|
40
|
+
@err = Blather::StreamError.import stream_error_node(@err_name, @msg)
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'provides a err_name attribute' do
|
@@ -65,7 +67,10 @@ describe 'Blather::StreamError when instantiated' do
|
|
65
67
|
|
66
68
|
it 'can be turned into xml' do
|
67
69
|
@err.must_respond_to :to_xml
|
68
|
-
@err.to_xml
|
70
|
+
doc = parse_stanza @err.to_xml
|
71
|
+
doc.xpath("//err_ns:internal-server-error", :err_ns => Blather::StreamError::STREAM_ERR_NS).wont_be_empty
|
72
|
+
doc.xpath("//err_ns:text[.='the server has experienced a misconfiguration']", :err_ns => Blather::StreamError::STREAM_ERR_NS).wont_be_empty
|
73
|
+
doc.xpath("//err_ns:extra-error[.='Blather Error']", :err_ns => 'blather:stream:error').wont_be_empty
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
@@ -96,7 +101,7 @@ describe 'Each XMPP stream error type' do
|
|
96
101
|
xml-not-well-formed
|
97
102
|
].each do |error_type|
|
98
103
|
it "handles the name for #{error_type}" do
|
99
|
-
e = StreamError.import stream_error_node(error_type)
|
104
|
+
e = Blather::StreamError.import stream_error_node(error_type)
|
100
105
|
e.name.must_equal error_type.gsub('-','_').to_sym
|
101
106
|
end
|
102
107
|
end
|
data/spec/blather/errors_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Blather::BlatherError do
|
4
4
|
it 'is handled by :error' do
|
5
|
-
BlatherError.new.handler_heirarchy.must_equal [:error]
|
5
|
+
Blather::BlatherError.new.handler_heirarchy.must_equal [:error]
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'Blather::ParseError' do
|
10
|
-
before { @error = ParseError.new('</generate-parse-error>"') }
|
10
|
+
before { @error = Blather::ParseError.new('</generate-parse-error>"') }
|
11
11
|
|
12
12
|
it 'is registers with the handler heirarchy' do
|
13
13
|
@error.handler_heirarchy.must_equal [:parse_error, :error]
|
@@ -19,14 +19,8 @@ describe 'Blather::ParseError' do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe 'Blather::TLSFailure' do
|
23
|
-
it 'is registers with the handler heirarchy' do
|
24
|
-
TLSFailure.new.handler_heirarchy.must_equal [:tls_failure, :error]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
22
|
describe 'Blather::UnknownResponse' do
|
29
|
-
before { @error = UnknownResponse.new(XMPPNode.new('foo-bar')) }
|
23
|
+
before { @error = Blather::UnknownResponse.new(Blather::XMPPNode.new('foo-bar')) }
|
30
24
|
|
31
25
|
it 'is registers with the handler heirarchy' do
|
32
26
|
@error.handler_heirarchy.must_equal [:unknown_response_error, :error]
|
@@ -37,4 +31,3 @@ describe 'Blather::UnknownResponse' do
|
|
37
31
|
@error.node.element_name.must_equal 'foo-bar'
|
38
32
|
end
|
39
33
|
end
|
40
|
-
|
data/spec/blather/jid_spec.rb
CHANGED
@@ -1,83 +1,84 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
|
2
2
|
|
3
|
-
describe
|
4
|
-
it 'does nothing if creaded from JID' do
|
5
|
-
jid = JID.new 'n@d/r'
|
6
|
-
JID.new(jid).object_id.must_equal jid.object_id
|
3
|
+
describe Blather::JID do
|
4
|
+
it 'does nothing if creaded from Blather::JID' do
|
5
|
+
jid = Blather::JID.new 'n@d/r'
|
6
|
+
Blather::JID.new(jid).object_id.must_equal jid.object_id
|
7
7
|
end
|
8
8
|
|
9
|
-
it 'creates a new JID from (n,d,r)' do
|
10
|
-
jid = JID.new('n', 'd', 'r')
|
9
|
+
it 'creates a new Blather::JID from (n,d,r)' do
|
10
|
+
jid = Blather::JID.new('n', 'd', 'r')
|
11
11
|
jid.node.must_equal 'n'
|
12
12
|
jid.domain.must_equal 'd'
|
13
13
|
jid.resource.must_equal 'r'
|
14
14
|
end
|
15
15
|
|
16
|
-
it 'creates a new JID from (n,d)' do
|
17
|
-
jid = JID.new('n', 'd')
|
16
|
+
it 'creates a new Blather::JID from (n,d)' do
|
17
|
+
jid = Blather::JID.new('n', 'd')
|
18
18
|
jid.node.must_equal 'n'
|
19
19
|
jid.domain.must_equal 'd'
|
20
20
|
end
|
21
21
|
|
22
|
-
it 'creates a new JID from (n@d)' do
|
23
|
-
jid = JID.new('n@d')
|
22
|
+
it 'creates a new Blather::JID from (n@d)' do
|
23
|
+
jid = Blather::JID.new('n@d')
|
24
24
|
jid.node.must_equal 'n'
|
25
25
|
jid.domain.must_equal 'd'
|
26
26
|
end
|
27
27
|
|
28
|
-
it 'creates a new JID from (n@d/r)' do
|
29
|
-
jid = JID.new('n@d/r')
|
28
|
+
it 'creates a new Blather::JID from (n@d/r)' do
|
29
|
+
jid = Blather::JID.new('n@d/r')
|
30
30
|
jid.node.must_equal 'n'
|
31
31
|
jid.domain.must_equal 'd'
|
32
32
|
jid.resource.must_equal 'r'
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'requires at least a node' do
|
36
|
-
proc { JID.new }.must_raise ArgumentError
|
36
|
+
proc { Blather::JID.new }.must_raise ::ArgumentError
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'ensures length of node is no more than 1023 characters' do
|
40
|
-
proc { JID.new('n'*1024) }.must_raise Blather::ArgumentError
|
40
|
+
proc { Blather::JID.new('n'*1024) }.must_raise Blather::ArgumentError
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'ensures length of domain is no more than 1023 characters' do
|
44
|
-
proc { JID.new('n', 'd'*1024) }.must_raise Blather::ArgumentError
|
44
|
+
proc { Blather::JID.new('n', 'd'*1024) }.must_raise Blather::ArgumentError
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'ensures length of resource is no more than 1023 characters' do
|
48
|
-
proc { JID.new('n', 'd', 'r'*1024) }.must_raise Blather::ArgumentError
|
48
|
+
proc { Blather::JID.new('n', 'd', 'r'*1024) }.must_raise Blather::ArgumentError
|
49
49
|
end
|
50
50
|
|
51
|
-
it 'compares JIDs' do
|
52
|
-
(JID.new('a@b/c') <=> JID.new('d@e/f')).must_equal -1
|
53
|
-
(JID.new('a@b/c') <=> JID.new('a@b/c')).must_equal 0
|
54
|
-
(JID.new('d@e/f') <=> JID.new('a@b/c')).must_equal 1
|
51
|
+
it 'compares Blather::JIDs' do
|
52
|
+
(Blather::JID.new('a@b/c') <=> Blather::JID.new('d@e/f')).must_equal -1
|
53
|
+
(Blather::JID.new('a@b/c') <=> Blather::JID.new('a@b/c')).must_equal 0
|
54
|
+
(Blather::JID.new('d@e/f') <=> Blather::JID.new('a@b/c')).must_equal 1
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'checks for equality' do
|
58
|
-
(JID.new('n@d/r') == JID.new('n@d/r')).must_equal true
|
58
|
+
(Blather::JID.new('n@d/r') == Blather::JID.new('n@d/r')).must_equal true
|
59
|
+
Blather::JID.new('n@d/r').eql?(Blather::JID.new('n@d/r')).must_equal true
|
59
60
|
end
|
60
61
|
|
61
62
|
it 'will strip' do
|
62
|
-
jid = JID.new('n@d/r')
|
63
|
-
jid.stripped.must_equal JID.new('n@d')
|
64
|
-
jid.must_equal JID.new('n@d/r')
|
63
|
+
jid = Blather::JID.new('n@d/r')
|
64
|
+
jid.stripped.must_equal Blather::JID.new('n@d')
|
65
|
+
jid.must_equal Blather::JID.new('n@d/r')
|
65
66
|
end
|
66
67
|
|
67
68
|
it 'will strip itself' do
|
68
|
-
jid = JID.new('n@d/r')
|
69
|
+
jid = Blather::JID.new('n@d/r')
|
69
70
|
jid.strip!
|
70
|
-
jid.must_equal JID.new('n@d')
|
71
|
+
jid.must_equal Blather::JID.new('n@d')
|
71
72
|
end
|
72
73
|
|
73
74
|
it 'has a string representation' do
|
74
|
-
JID.new('n@d/r').to_s.must_equal 'n@d/r'
|
75
|
-
JID.new('n', 'd', 'r').to_s.must_equal 'n@d/r'
|
76
|
-
JID.new('n', 'd').to_s.must_equal 'n@d'
|
75
|
+
Blather::JID.new('n@d/r').to_s.must_equal 'n@d/r'
|
76
|
+
Blather::JID.new('n', 'd', 'r').to_s.must_equal 'n@d/r'
|
77
|
+
Blather::JID.new('n', 'd').to_s.must_equal 'n@d'
|
77
78
|
end
|
78
79
|
|
79
80
|
it 'provides a #stripped? helper' do
|
80
|
-
jid = JID.new 'a@b/c'
|
81
|
+
jid = Blather::JID.new 'a@b/c'
|
81
82
|
jid.must_respond_to :stripped?
|
82
83
|
jid.stripped?.wont_equal true
|
83
84
|
jid.strip!
|