<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>spec/test_helper.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,8 @@
+verbose true
+
 desc &quot;Run the unit tests&quot;
 task :test do
-	sh &quot;spec -f s -c spec/daemon_controller_spec.rb&quot;
+	sh &quot;spec -f s -c spec/*_spec.rb&quot;
 end
 
 task &quot;package:gem&quot; do</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
       &quot;README.markdown&quot;, &quot;LICENSE.txt&quot;, &quot;daemon_controller.gemspec&quot;,
       &quot;lib/daemon_controller.rb&quot;,
       &quot;lib/daemon_controller/lock_file.rb&quot;,
+      &quot;spec/test_helper.rb&quot;,
       &quot;spec/daemon_controller_spec.rb&quot;,
       &quot;spec/echo_server.rb&quot;
   ]</diff>
      <filename>daemon_controller.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -1,85 +1,14 @@
-$LOAD_PATH &lt;&lt; File.expand_path(File.join(File.dirname(__FILE__), &quot;..&quot;, &quot;lib&quot;))
-Dir.chdir(File.dirname(__FILE__))
+require File.join(File.dirname(__FILE__), &quot;test_helper&quot;)
 require 'daemon_controller'
 require 'benchmark'
 require 'socket'
 
-# A thread which doesn't execute its block until the
-# 'go!' method has been called.
-class WaitingThread &lt; Thread
-	def initialize
-		super do
-			@mutex = Mutex.new
-			@cond = ConditionVariable.new
-			@go = false
-			@mutex.synchronize do
-				while !@go
-					@cond.wait(@mutex)
-				end
-			end
-			yield
-		end
-	end
-	
-	def go!
-		@mutex.synchronize do
-			@go = true
-			@cond.broadcast
-		end
-	end
-end
-
-module TestHelpers
-	def new_controller(options = {})
-		start_command = './echo_server.rb -l echo_server.log -P echo_server.pid'
-		if options[:wait1]
-			start_command &lt;&lt; &quot; --wait1 #{options[:wait1]}&quot;
-		end
-		if options[:wait2]
-			start_command &lt;&lt; &quot; --wait2 #{options[:wait2]}&quot;
-		end
-		if options[:stop_time]
-			start_command &lt;&lt; &quot; --stop-time #{options[:stop_time]}&quot;
-		end
-		if options[:crash_before_bind]
-			start_command &lt;&lt; &quot; --crash-before-bind&quot;
-		end
-		new_options = {
-			:identifier    =&gt; 'My Test Daemon',
-			:start_command =&gt; start_command,
-			:ping_command  =&gt; proc do
-				begin
-					TCPSocket.new('localhost', 3230)
-					true
-				rescue SystemCallError
-					false
-				end
-			end,
-			:pid_file      =&gt; 'echo_server.pid',
-			:log_file      =&gt; 'echo_server.log',
-			:start_timeout =&gt; 3,
-			:stop_timeout  =&gt; 3
-		}.merge(options)
-		@controller = DaemonController.new(new_options)
-	end
-	
-	def write_file(filename, contents)
-		File.open(filename, 'w') do |f|
-			f.write(contents)
-		end
-	end
-	
-	def exec_is_slow?
-		return RUBY_PLATFORM == &quot;java&quot;
-	end
-end
-
 describe DaemonController, &quot;#start&quot; do
 	before :each do
 		new_controller
 	end
 	
-	include TestHelpers
+	include TestHelper
 	
 	it &quot;works&quot; do
 		@controller.start
@@ -92,19 +21,19 @@ describe DaemonController, &quot;#start&quot; do
 	end
 	
 	it &quot;deletes existing PID file before starting the daemon&quot; do
-		write_file('echo_server.pid', '1234')
+		write_file('spec/echo_server.pid', '1234')
 		@controller.should_receive(:daemon_is_running?).and_return(false)
 		@controller.should_receive(:spawn_daemon)
 		@controller.should_receive(:pid_file_available?).and_return(true)
 		@controller.should_receive(:run_ping_command).at_least(:once).and_return(true)
 		@controller.start
-		File.exist?('echo_server.pid').should be_false
+		File.exist?('spec/echo_server.pid').should be_false
 	end
 	
 	it &quot;blocks until the daemon has written to its PID file&quot; do
 		thread = WaitingThread.new do
 			sleep 0.15
-			write_file('echo_server.pid', '1234')
+			write_file('spec/echo_server.pid', '1234')
 		end
 		@controller.should_receive(:daemon_is_running?).and_return(false)
 		@controller.should_receive(:spawn_daemon).and_return do
@@ -188,14 +117,14 @@ describe DaemonController, &quot;#start&quot; do
 			# It's possible that because of a racing condition, the PID
 			# file doesn't get deleted before the next test is run. So
 			# here we ensure that the PID file is gone.
-			File.unlink(&quot;echo_server.pid&quot;) rescue nil
+			File.unlink(&quot;spec/echo_server.pid&quot;) rescue nil
 		end
 	end
 	
 	if DaemonController.send(:fork_supported?)
 		it &quot;kills the daemon if it doesn't start in time and hasn't &quot; &lt;&lt;
 		   &quot;forked yet, on platforms where Ruby supports fork()&quot; do
-			new_controller(:start_command =&gt; '(echo $$ &gt; echo_server.pid &amp;&amp; sleep 5)',
+			new_controller(:start_command =&gt; '(echo $$ &gt; spec/echo_server.pid &amp;&amp; sleep 5)',
 				:start_timeout =&gt; 0.3)
 			lambda { @controller.start }.should raise_error(DaemonController::StartTimeout)
 		end
@@ -232,12 +161,16 @@ describe DaemonController, &quot;#start&quot; do
 end
 
 describe DaemonController, &quot;#stop&quot; do
-	include TestHelpers
+	include TestHelper
 	
 	before :each do
 		new_controller
 	end
 	
+	after :each do
+		@controller.stop
+	end
+	
 	it &quot;raises no exception if the daemon is not running&quot; do
 		@controller.stop
 	end
@@ -283,7 +216,7 @@ describe DaemonController, &quot;#stop&quot; do
 end
 
 describe DaemonController, &quot;#connect&quot; do
-	include TestHelpers
+	include TestHelper
 	
 	before :each do
 		new_controller
@@ -311,7 +244,7 @@ describe DaemonController, &quot;#connect&quot; do
 end
 
 describe DaemonController do
-	include TestHelpers
+	include TestHelper
 	
 	specify &quot;if the ping command is a block that raises Errno::ECONNREFUSED, then that's &quot; &lt;&lt;
 	        &quot;an indication that the daemon cannot be connected to&quot; do</diff>
      <filename>spec/daemon_controller_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>9a1fbe6cac534c974a2e139ec7a5cfd8c4c06425</id>
    </parent>
  </parents>
  <author>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </author>
  <url>http://github.com/FooBarWidget/daemon_controller/commit/3ac2359fa75b358f630f44c9164298069eee143b</url>
  <id>3ac2359fa75b358f630f44c9164298069eee143b</id>
  <committed-date>2009-02-25T08:41:12-08:00</committed-date>
  <authored-date>2009-02-25T08:40:43-08:00</authored-date>
  <message>Refactor unit tests.</message>
  <tree>3ef36d91ebdbb0ec0d79171a319d4e1a869c4e00</tree>
  <committer>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </committer>
</commit>
