test/stanza/iq/disco_items_test.rb in vines-0.4.5 vs test/stanza/iq/disco_items_test.rb in vines-0.4.6

- old
+ new

@@ -1,47 +1,49 @@ # encoding: UTF-8 -require 'tmpdir' -require 'vines' -require 'ext/nokogiri' -require 'minitest/autorun' +require 'test_helper' -class DiscoItemsTest < MiniTest::Unit::TestCase - def setup - @stream = MiniTest::Mock.new - end - - def test_component_items - query = %q{<query xmlns="http://jabber.org/protocol/disco#items"/>} - node = node(%Q{<iq id="42" to="wonderland.lit" type="get">#{query}</iq>}) - - expected = node(%q{ - <iq from="wonderland.lit" id="42" to="alice@wonderland.lit/home" type="result"> - <query xmlns="http://jabber.org/protocol/disco#items"> - <item jid="cake.wonderland.lit"/> - <item jid="tea.wonderland.lit"/> - </query> - </iq> - }.strip.gsub(/\n|\s{2,}/, '')) - - config = Vines::Config.new do +describe Vines::Stanza::Iq::DiscoItems do + subject { Vines::Stanza::Iq::DiscoItems.new(xml, stream) } + let(:stream) { MiniTest::Mock.new } + let(:alice) { Vines::User.new(jid: 'alice@wonderland.lit/home') } + let(:config) do + Vines::Config.new do host 'wonderland.lit' do storage(:fs) { dir Dir.tmpdir } components 'tea' => 'secr3t', 'cake' => 'passw0rd' end end + end - @stream.expect(:user, Vines::User.new(:jid => 'alice@wonderland.lit/home')) - @stream.expect(:write, nil, [expected]) - @stream.expect(:config, config) - - stanza = Vines::Stanza::Iq::DiscoItems.new(node, @stream) - stanza.process - assert @stream.verify + before do + class << stream + attr_accessor :config, :user + end + stream.config = config + stream.user = alice end - private + describe 'when querying server items' do + let(:xml) do + query = %q{<query xmlns="http://jabber.org/protocol/disco#items"/>} + node(%Q{<iq id="42" to="wonderland.lit" type="get">#{query}</iq>}) + end - def node(xml) - Nokogiri::XML(xml).root + let(:result) do + node(%q{ + <iq from="wonderland.lit" id="42" to="alice@wonderland.lit/home" type="result"> + <query xmlns="http://jabber.org/protocol/disco#items"> + <item jid="cake.wonderland.lit"/> + <item jid="tea.wonderland.lit"/> + </query> + </iq> + }) + end + + it 'includes component domains in output' do + stream.expect :write, nil, [result] + subject.process + stream.verify + end end end