Permalink
Browse files

Convert to specs.

  • Loading branch information...
1 parent 668862b commit bbfe797aa88328ea307805003272d38a999e7fd9 @dgraham dgraham committed Sep 17, 2012
Showing with 36 additions and 34 deletions.
  1. +36 −34 test/stanza/iq/disco_items_test.rb
@@ -1,47 +1,49 @@
# encoding: UTF-8
-require 'tmpdir'
-require 'vines'
-require 'ext/nokogiri'
-require 'minitest/autorun'
-
-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
+require 'test_helper'
+
+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
+
+ 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
- def node(xml)
- Nokogiri::XML(xml).root
+ it 'includes component domains in output' do
+ stream.expect :write, nil, [result]
+ subject.process
+ stream.verify
+ end
end
end

0 comments on commit bbfe797

Please sign in to comment.