spec/blather/errors/stream_error_spec.rb in blather-0.3.4 vs spec/blather/errors/stream_error_spec.rb in blather-0.4.0
- old
+ new
@@ -1,43 +1,45 @@
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
def stream_error_node(error = 'internal-server-error', msg = nil)
- node = XMPPNode.new('stream:error')
- XML::Document.new.root = node
+ node = Blather::XMPPNode.new('error')
+ node.namespace = {'stream' => Blather::Stream::STREAM_NS}
- err = XMPPNode.new(error)
+ node << (err = Blather::XMPPNode.new(error, node.document))
err.namespace = 'urn:ietf:params:xml:ns:xmpp-streams'
- node << err
if msg
- text = XMPPNode.new('text')
+ node << (text = Blather::XMPPNode.new('text', node.document))
text.namespace = 'urn:ietf:params:xml:ns:xmpp-streams'
- text << msg
- node << text
+ text.content = msg
end
- extra = XMPPNode.new('extra-error')
+ node << (extra = Blather::XMPPNode.new('extra-error', node.document))
extra.namespace = 'blather:stream:error'
- extra << 'Blather Error'
+ extra.content = 'Blather Error'
- node << extra
node
end
describe 'Blather::StreamError' do
it 'can import a node' do
- StreamError.must_respond_to :import
- e = StreamError.import stream_error_node
- e.must_be_kind_of StreamError
+ err = stream_error_node 'internal-server-error', 'the message'
+ Blather::StreamError.must_respond_to :import
+ e = Blather::StreamError.import err
+ e.must_be_kind_of Blather::StreamError
+
+ e.name.must_equal :internal_server_error
+ e.text.must_equal 'the message'
+ e.extras.must_equal err.find('descendant::*[name()="extra-error"]', 'blather:stream:error').map {|n|n}
end
end
describe 'Blather::StreamError when instantiated' do
before do
@err_name = 'internal-server-error'
@msg = 'the server has experienced a misconfiguration'
- @err = StreamError.import stream_error_node(@err_name, @msg)
+ @err = Blather::StreamError.import stream_error_node(@err_name, @msg)
end
it 'provides a err_name attribute' do
@err.must_respond_to :name
@err.name.must_equal @err_name.gsub('-','_').to_sym
@@ -63,11 +65,14 @@
@err.inspect.must_match(/#{@msg}/)
end
it 'can be turned into xml' do
@err.must_respond_to :to_xml
- @err.to_xml.must_equal "<stream:error>\n<internal-server-error xmlns=\"urn:ietf:params:xml:ns:xmpp-streams\"/>\n<text xmlns=\"urn:ietf:params:xml:ns:xmpp-streams\">the server has experienced a misconfiguration</text>\n<extra-error xmlns=\"blather:stream:error\">Blather Error</extra-error>\n</stream:error>"
+ doc = parse_stanza @err.to_xml
+ doc.xpath("//err_ns:internal-server-error", :err_ns => Blather::StreamError::STREAM_ERR_NS).wont_be_empty
+ doc.xpath("//err_ns:text[.='the server has experienced a misconfiguration']", :err_ns => Blather::StreamError::STREAM_ERR_NS).wont_be_empty
+ doc.xpath("//err_ns:extra-error[.='Blather Error']", :err_ns => 'blather:stream:error').wont_be_empty
end
end
describe 'Each XMPP stream error type' do
%w[ bad-format
@@ -94,10 +99,10 @@
unsupported-stanza-type
unsupported-version
xml-not-well-formed
].each do |error_type|
it "handles the name for #{error_type}" do
- e = StreamError.import stream_error_node(error_type)
+ e = Blather::StreamError.import stream_error_node(error_type)
e.name.must_equal error_type.gsub('-','_').to_sym
end
end
end