aboutsummaryrefslogtreecommitdiffstats
path: root/script
diff options
context:
space:
mode:
authorlouise <louise>2007-10-16 19:50:11 +0000
committerlouise <louise>2007-10-16 19:50:11 +0000
commit254c3a4bcde7d82dd8a3d7cafeb6a8fcf22cd433 (patch)
tree74f8a3c2b400f265fa986dd8dc2e9cf8154aaf3f /script
parent115f71d49e4552874b430afe292aac22f832d5fa (diff)
Adding rspec config files, initial specs
Diffstat (limited to 'script')
-rwxr-xr-xscript/spec4
-rwxr-xr-xscript/spec_server86
2 files changed, 90 insertions, 0 deletions
diff --git a/script/spec b/script/spec
new file mode 100755
index 000000000..d318f1ae3
--- /dev/null
+++ b/script/spec
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
+require 'spec'
+::Spec::Runner::CommandLine.run(ARGV, STDERR, STDOUT, true, true)
diff --git a/script/spec_server b/script/spec_server
new file mode 100755
index 000000000..cac91e2b8
--- /dev/null
+++ b/script/spec_server
@@ -0,0 +1,86 @@
+#!/usr/bin/env ruby
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
+require 'rubygems'
+require 'drb/drb'
+require 'rbconfig'
+require 'spec'
+require 'optparse'
+specmate = ENV['HOME'] + "/Library/Application\ Support/TextMate/Bundles/RSpec.tmbundle/Support/lib"
+if File.directory?(specmate)
+ $LOAD_PATH.unshift(specmate)
+ require 'text_mate_formatter'
+end
+
+# This is based on Florian Weber's TDDMate
+
+module Spec
+ module Runner
+ class RailsSpecServer
+ def run(args, stderr, stdout)
+ $stdout = stdout
+ $stderr = stderr
+
+ ::Dispatcher.reset_application!
+ ::Dependencies.mechanism = :load
+ require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
+ load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
+
+ ::Spec::Runner::CommandLine.run(args, stderr, stdout, false, true)
+ end
+ end
+ end
+end
+puts "Loading Rails environment"
+
+ENV["RAILS_ENV"] = "test"
+require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
+require 'dispatcher'
+
+def restart_test_server
+ puts "restarting"
+ config = ::Config::CONFIG
+ ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
+ command_line = [ruby, $0, ARGV].flatten.join(' ')
+ exec(command_line)
+end
+
+def daemonize(pid_file = nil)
+ return yield if $DEBUG
+ pid = Process.fork{
+ Process.setsid
+ Dir.chdir(RAILS_ROOT)
+ trap("SIGINT"){ exit! 0 }
+ trap("SIGTERM"){ exit! 0 }
+ trap("SIGHUP"){ restart_test_server }
+ File.open("/dev/null"){|f|
+ STDERR.reopen f
+ STDIN.reopen f
+ STDOUT.reopen f
+ }
+ yield
+ }
+ puts "spec_server launched. (PID: %d)" % pid
+ File.open(pid_file,"w"){|f| f.puts pid } if pid_file
+ exit! 0
+end
+
+options = Hash.new
+opts = OptionParser.new
+opts.on("-d", "--daemon"){|v| options[:daemon] = true }
+opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v }
+opts.parse!(ARGV)
+
+puts "Ready"
+exec_server = lambda {
+ trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
+ DRb.start_service("druby://localhost:8989", Spec::Runner::RailsSpecServer.new)
+ DRb.thread.join
+}
+
+if options[:daemon]
+ daemonize(options[:pid], &exec_server)
+else
+ exec_server.call
+end
+