Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert to specs.

  • Loading branch information...
commit 81ef90efdd07c81c770a722b7b23fc42c2c2ca67 1 parent 722c9bf
@dgraham dgraham authored
Showing with 53 additions and 49 deletions.
  1. +53 −49 test/stanza/iq_test.rb
View
102 test/stanza/iq_test.rb
@@ -1,66 +1,70 @@
# encoding: UTF-8
-require 'tmpdir'
-require 'vines'
-require 'ext/nokogiri'
-require 'minitest/autorun'
+require 'test_helper'
-class IqTest < MiniTest::Unit::TestCase
- def setup
- @stream = MiniTest::Mock.new
- @config = Vines::Config.new do
+describe Vines::Stanza::Iq do
+ subject { Vines::Stanza::Iq.new(xml, stream) }
+ let(:stream) { MiniTest::Mock.new }
+ let(:alice) { Vines::User.new(jid: 'alice@wonderland.lit/tea') }
+ let(:hatter) { Vines::User.new(jid: 'hatter@wonderland.lit/crumpets') }
+ let(:config) do
+ Vines::Config.new do
host 'wonderland.lit' do
storage(:fs) { dir Dir.tmpdir }
end
end
end
- def test_allow_other_iq_to_route
- alice = Vines::User.new(:jid => 'alice@wonderland.lit/tea')
- hatter = Vines::User.new(:jid => 'hatter@wonderland.lit/crumpets')
- node = node(%q{
- <iq id="42" type="set" to="alice@wonderland.lit/tea" from="hatter@wonderland.lit/crumpets">
- <si xmlns="http://jabber.org/protocol/si" id="42_si" profile="http://jabber.org/protocol/si/profile/file-transfer">
- <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="file" size="1"/>
- <feature xmlns="http://jabber.org/protocol/feature-neg">
- <x xmlns="jabber:x:data" type="form">
- <field var="stream-method" type="list-single">
- <option>
- <value>http://jabber.org/protocol/bytestreams</value>
- </option>
- <option>
- <value>http://jabber.org/protocol/ibb</value>
- </option>
- </field>
- </x>
- </feature>
- </si>
- </iq>
- }.strip.gsub(/\n|\s{2,}/, ''))
-
- recipient = MiniTest::Mock.new
- recipient.expect(:user, alice, [])
- recipient.expect(:write, nil, [node])
+ before do
+ class << stream
+ attr_accessor :config, :user
+ end
+ stream.user = hatter
+ stream.config = config
+ end
- @stream.expect(:config, @config)
- @stream.expect(:user, hatter)
- @stream.expect(:connected_resources, [recipient], [alice.jid])
+ describe 'when addressed to a user rather than the server itself' do
+ let(:recipient) { MiniTest::Mock.new }
+ let(:xml) do
+ node(%q{
+ <iq id="42" type="set" to="alice@wonderland.lit/tea" from="hatter@wonderland.lit/crumpets">
+ <si xmlns="http://jabber.org/protocol/si" id="42_si" profile="http://jabber.org/protocol/si/profile/file-transfer">
+ <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="file" size="1"/>
+ <feature xmlns="http://jabber.org/protocol/feature-neg">
+ <x xmlns="jabber:x:data" type="form">
+ <field var="stream-method" type="list-single">
+ <option>
+ <value>http://jabber.org/protocol/bytestreams</value>
+ </option>
+ <option>
+ <value>http://jabber.org/protocol/ibb</value>
+ </option>
+ </field>
+ </x>
+ </feature>
+ </si>
+ </iq>
+ })
+ end
- stanza = Vines::Stanza::Iq.new(node, @stream)
- stanza.process
- assert @stream.verify
- assert recipient.verify
- end
+ before do
+ recipient.expect :user, alice, []
+ recipient.expect :write, nil, [xml]
+ stream.expect :connected_resources, [recipient], [alice.jid]
+ end
- def test_feature_not_implemented
- node = node('<iq type="set" id="42"/>')
- stanza = Vines::Stanza::Iq.new(node, @stream)
- assert_raises(Vines::StanzaErrors::FeatureNotImplemented) { stanza.process }
+ it 'routes the stanza to the users connected resources' do
+ subject.process
+ stream.verify
+ recipient.verify
+ end
end
- private
+ describe 'when given no type or body elements' do
+ let(:xml) { node('<iq type="set" id="42"/>') }
- def node(xml)
- Nokogiri::XML(xml).root
+ it 'raises a feature-not-implemented stanza error' do
+ -> { subject.process }.must_raise Vines::StanzaErrors::FeatureNotImplemented
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.