test/stream/server/ready_test.rb in vines-0.2.1 vs test/stream/server/ready_test.rb in vines-0.3.0

- old
+ new

@@ -8,20 +8,14 @@ def setup @stream = MiniTest::Mock.new @state = Vines::Stream::Server::Ready.new(@stream, nil) def @state.to_stanza(node) - if node.name == 'bogus' - nil - else - MiniTest::Mock.new.tap do |stanza| - stanza.expect(:process, nil) - stanza.class.send(:define_method, :[]) do |a| - node[a] - end - ServerReadyTest::STANZAS << stanza - end + Vines::Stanza.from_node(node, @stream).tap do |stanza| + def stanza.process + ServerReadyTest::STANZAS << self + end if stanza end end end def teardown @@ -33,11 +27,10 @@ @stream.expect(:domain, 'verona.lit') @stream.expect(:user=, nil, [Vines::User.new(:jid => 'alice@wonderland.lit')]) node = node(%Q{<message from="alice@wonderland.lit" to="romeo@verona.lit"/>}) @state.node(node) assert_equal 1, STANZAS.size - assert STANZAS.map {|s| s.verify }.all? assert @stream.verify end def test_unsupported_stanza_type node = node('<bogus/>') @@ -47,48 +40,48 @@ end def test_improper_addressing_missing_to node = node(%Q{<message from="alice@wonderland.lit"/>}) assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) } - assert_equal 1, STANZAS.size + assert STANZAS.empty? assert @stream.verify end - def test_improper_addressing_empty_to + def test_improper_addressing_invalid_to node = node(%Q{<message from="alice@wonderland.lit" to=" "/>}) - assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) } - assert_equal 1, STANZAS.size + assert_raises(Vines::StanzaErrors::JidMalformed) { @state.node(node) } + assert STANZAS.empty? assert @stream.verify end def test_improper_addressing_missing_from node = node(%Q{<message to="romeo@verona.lit"/>}) assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) } - assert_equal 1, STANZAS.size + assert STANZAS.empty? assert @stream.verify end - def test_improper_addressing_empty_from + def test_improper_addressing_invalid_from node = node(%Q{<message from=" " to="romeo@verona.lit"/>}) - assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) } - assert_equal 1, STANZAS.size + assert_raises(Vines::StanzaErrors::JidMalformed) { @state.node(node) } + assert STANZAS.empty? assert @stream.verify end def test_invalid_from @stream.expect(:remote_domain, 'wonderland.lit') node = node(%Q{<message from="alice@bogus.lit" to="romeo@verona.lit"/>}) assert_raises(Vines::StreamErrors::InvalidFrom) { @state.node(node) } - assert_equal 1, STANZAS.size + assert STANZAS.empty? assert @stream.verify end def test_host_unknown @stream.expect(:remote_domain, 'wonderland.lit') @stream.expect(:domain, 'verona.lit') node = node(%Q{<message from="alice@wonderland.lit" to="romeo@bogus.lit"/>}) assert_raises(Vines::StreamErrors::HostUnknown) { @state.node(node) } - assert_equal 1, STANZAS.size + assert STANZAS.empty? assert @stream.verify end private