2 $LOAD_PATH.unshift File
.dirname(__FILE__
) + '/../../rspec/lib' # For svn
3 $LOAD_PATH.unshift File
.dirname(__FILE__
) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
10 # This is based on Florian Weber's TDDMate
14 def run(argv, stderr, stdout)
18 base
= ActiveRecord
::Base
19 def base
.clear_reloadable_connections
!
20 active_connections
.each
do |name
, conn
|
21 if conn
.requires_reloading
?
23 active_connections
.delete(name
)
28 if ::Dispatcher.respond_to
?(:cleanup_application)
29 ::Dispatcher.cleanup_application
30 elsif ::Dispatcher.respond_to
?(:reset_application!)
31 ::Dispatcher.reset_application
!
33 ::Dependencies.mechanism
= :load
34 require_dependency('application.rb') unless Object
.const_defined
?(:ApplicationController)
35 load File
.dirname(__FILE__
) + '/../spec/spec_helper.rb'
37 ::Spec::Runner::CommandLine.run(
38 ::Spec::Runner::OptionParser.parse(
48 puts
"Loading Rails environment"
50 ENV["RAILS_ENV"] = "test"
51 require File
.expand_path(File
.dirname(__FILE__
) + "/../config/environment")
54 def restart_test_server
56 config
= ::Config::CONFIG
57 ruby
= File
::join(config
['bindir'], config
['ruby_install_name']) + config
['EXEEXT']
58 command_line
= [ruby
, $0, ARGV].flatten
.join(' ')
62 def daemonize(pid_file
= nil)
63 return yield if $DEBUG
67 trap("SIGINT"){ exit
! 0 }
68 trap("SIGTERM"){ exit
! 0 }
69 trap("SIGHUP"){ restart_test_server
}
70 File
.open("/dev/null"){|f
|
77 puts
"spec_server launched. (PID: %d)" % pid
78 File
.open(pid_file
,"w"){|f
| f
.puts pid
} if pid_file
83 opts
= OptionParser
.new
84 opts
.on("-d", "--daemon"){|v
| options
[:daemon] = true }
85 opts
.on("-p", "--pid PIDFILE"){|v
| options
[:pid] = v
}
89 exec_server
= lambda
{
90 trap("USR2") { restart_test_server
} if Signal
.list
.has_key
?("USR2")
91 DRb
.start_service("druby://localhost:8989", Spec
::Runner::RailsSpecServer.new
)
96 daemonize(options
[:pid], &exec_server
)