test/stanza/message_test.rb in vines-0.1.0 vs test/stanza/message_test.rb in vines-0.1.1
- old
+ new
@@ -1,38 +1,39 @@
# encoding: UTF-8
require 'vines'
require 'ext/nokogiri'
-require 'minitest/mock'
-require 'test/unit'
+require 'minitest/autorun'
-class MessageTest < Test::Unit::TestCase
+class MessageTest < MiniTest::Unit::TestCase
def setup
@stream = MiniTest::Mock.new
end
def test_bad_type_returns_error
node = node('<message type="bogus">hello!</message>')
stanza = Vines::Stanza::Message.new(node, @stream)
- assert_raise(Vines::StanzaErrors::BadRequest) { stanza.process }
+ assert_raises(Vines::StanzaErrors::BadRequest) { stanza.process }
end
def test_missing_to_address_is_sent_to_sender
alice = Vines::User.new(:jid => 'alice@wonderland.lit/tea')
node = node('<message>hello!</message>')
recipient = MiniTest::Mock.new
+ recipient.expect(:user, alice)
+ recipient.expect(:write, nil, [node])
+
router = MiniTest::Mock.new
router.expect(:local?, true, [node])
router.expect(:connected_resources, [recipient], [alice.jid.bare])
@stream.expect(:router, router)
@stream.expect(:user, alice)
- @stream.expect(:broadcast, nil, [node, [recipient]])
stanza = Vines::Stanza::Message.new(node, @stream)
- assert_nothing_raised { stanza.process }
+ stanza.process
assert @stream.verify
assert router.verify
assert recipient.verify
end
@@ -49,11 +50,11 @@
@stream.expect(:router, router)
@stream.expect(:storage, storage, [bogus.domain])
stanza = Vines::Stanza::Message.new(node, @stream)
- assert_nothing_raised { stanza.process }
+ stanza.process
assert @stream.verify
assert router.verify
assert storage.verify
end
@@ -70,30 +71,35 @@
@stream.expect(:router, router)
@stream.expect(:storage, storage, [hatter.jid.domain])
stanza = Vines::Stanza::Message.new(node, @stream)
- assert_raise(Vines::StanzaErrors::ServiceUnavailable) { stanza.process }
+ assert_raises(Vines::StanzaErrors::ServiceUnavailable) { stanza.process }
assert @stream.verify
assert router.verify
assert storage.verify
end
def test_message_to_local_user_in_different_domain_is_delivered
+ alice = Vines::User.new(:jid => 'alice@wonderland.lit/tea')
romeo = Vines::User.new(:jid => 'romeo@verona.lit/balcony')
node = node(%Q{<message to="#{romeo.jid}">hello!</message>})
+ expected = node(%Q{<message to="#{romeo.jid}" from="#{alice.jid}">hello!</message>})
recipient = MiniTest::Mock.new
+ recipient.expect(:user, romeo)
+ recipient.expect(:write, nil, [expected])
+
router = MiniTest::Mock.new
router.expect(:local?, true, [node])
router.expect(:connected_resources, [recipient], [romeo.jid])
@stream.expect(:router, router)
- @stream.expect(:broadcast, nil, [node, [recipient]])
+ @stream.expect(:user, alice)
stanza = Vines::Stanza::Message.new(node, @stream)
- assert_nothing_raised { stanza.process }
+ stanza.process
assert @stream.verify
assert router.verify
assert recipient.verify
end
@@ -109,10 +115,10 @@
@stream.expect(:router, router)
@stream.expect(:user, alice)
stanza = Vines::Stanza::Message.new(node, @stream)
- assert_nothing_raised { stanza.process }
+ stanza.process
assert @stream.verify
assert router.verify
end
private