Browse files

split out spec into runner and test; add rake task for running specs

  • Loading branch information...
1 parent 8d61568 commit d3b342ffc2be176ae9d3e47d6482ec82520b9080 @tmm1 committed Jun 25, 2008
Showing with 70 additions and 63 deletions.
  1. +5 −0 Rakefile
  2. +25 −0 spec/spec_runner.rb
  3. +40 −0 spec/xmpp4em_spec.rb
  4. +0 −63 xmpp4em_spec.rb
View
5 Rakefile
@@ -0,0 +1,5 @@
+task :default do
+ Dir.chdir('spec'){
+ sh 'bacon spec_runner.rb'
+ }
+end
View
25 spec/spec_runner.rb
@@ -0,0 +1,25 @@
+require 'bacon'
+$:.unshift File.dirname(__FILE__) + '/..'
+require 'xmpp4em'
+
+shared 'eventmachine' do
+ $bacon_thread = Thread.current
+ def wait
+ Thread.stop
+ EM.add_timer(10) do
+ wake
+ should.flunk('waited too long')
+ end
+ end
+ def wake
+ $bacon_thread.wakeup
+ end
+end
+
+EM.run{
+ Thread.new{
+ Thread.abort_on_exception = true
+ require 'xmpp4em_spec'
+ EM.stop_event_loop
+ }
+}
View
40 spec/xmpp4em_spec.rb
@@ -0,0 +1,40 @@
+describe 'XMPP4EM' do
+ behaves_like 'eventmachine'
+
+ @foo = XMPP4EM::Client.new('foo@localhost', 'test', :auto_register => true)
+ @bar = XMPP4EM::Client.new('bar@localhost', 'test', :auto_register => true)
+
+ should 'login to an xmpp server' do
+ @foo.on(:login) do
+ @foo.send Jabber::Presence.new
+ wake
+ end
+
+ @foo.connect
+ wait
+
+ @foo.should.be.connected?
+ end
+
+ should 'send messages to others' do
+ @bar.on(:login) do
+ @bar.send Jabber::Presence.new do
+ wake
+ end
+ end
+
+ received = nil
+ @bar.on(:message) do |msg|
+ received = msg.first_element_text('//body')
+ wake
+ end
+
+ @bar.connect
+ wait
+
+ @foo.send_msg 'bar@localhost', 'hello'
+ wait
+
+ received.should == 'hello'
+ end
+end
View
63 xmpp4em_spec.rb
@@ -1,63 +0,0 @@
-require 'xmpp4em'
-require 'bacon'
-
-shared 'eventmachine' do
- $bacon_thread = Thread.current
- def wait
- Thread.stop
- EM.add_timer(10) do
- wake
- should.flunk('waited too long')
- end
- end
- def wake
- $bacon_thread.wakeup
- end
-end
-
-EM.run{
- Thread.new{
- describe 'XMPP4EM' do
- behaves_like 'eventmachine'
-
- @foo = XMPP4EM::Client.new('foo@localhost', 'test', :auto_register => true)
- @bar = XMPP4EM::Client.new('bar@localhost', 'test', :auto_register => true)
-
- should 'login to an xmpp server' do
- @foo.on(:login) do
- @foo.send Jabber::Presence.new
- wake
- end
-
- @foo.connect
- wait
-
- @foo.should.be.connected?
- end
-
- should 'send messages to others' do
- @bar.on(:login) do
- @bar.send Jabber::Presence.new do
- wake
- end
- end
-
- received = nil
- @bar.on(:message) do |msg|
- received = msg.first_element_text('//body')
- wake
- end
-
- @bar.connect
- wait
-
- @foo.send_msg 'bar@localhost', 'hello'
- wait
-
- received.should == 'hello'
- end
-
- EM.stop_event_loop
- end
- }
-}

0 comments on commit d3b342f

Please sign in to comment.