| |   |
| 1 | #!/usr/bin/env ruby |
| 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 |
| 4 | require 'rubygems' |
| 5 | require 'drb/drb' |
| 6 | require 'rbconfig' |
| 7 | require 'spec' |
| 8 | require 'optparse' |
| 9 | specmate = ENV['HOME'] + "/Library/Application\ Support/TextMate/Bundles/RSpec.tmbundle/Support/lib" |
| 10 | if File.directory?(specmate) |
| 11 | $LOAD_PATH.unshift(specmate) |
| 12 | require 'text_mate_formatter' |
| 13 | end |
| 14 | |
| 15 | # This is based on Florian Weber's TDDMate |
| 16 | |
| 17 | module Spec |
| 18 | module Runner |
| 19 | class RailsSpecServer |
| 20 | def run(args, stderr, stdout) |
| 21 | $stdout = stdout |
| 22 | $stderr = stderr |
| 23 | |
| 24 | ::Dispatcher.reset_application! |
| 25 | ::Dependencies.mechanism = :load |
| 26 | require_dependency('application.rb') unless Object.const_defined?(:ApplicationController) |
| 27 | load File.dirname(__FILE__) + '/../spec/spec_helper.rb' |
| 28 | |
| 29 | ::Spec::Runner::CommandLine.run(args, stderr, stdout, false, true) |
| 30 | end |
| 31 | end |
| 32 | end |
| 33 | end |
| 34 | puts "Loading Rails environment" |
| 35 | |
| 36 | ENV["RAILS_ENV"] = "test" |
| 37 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") |
| 38 | require 'dispatcher' |
| 39 | |
| 40 | def restart_test_server |
| 41 | puts "restarting" |
| 42 | config = ::Config::CONFIG |
| 43 | ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT'] |
| 44 | command_line = [ruby, $0, ARGV].flatten.join(' ') |
| 45 | exec(command_line) |
| 46 | end |
| 47 | |
| 48 | def daemonize(pid_file = nil) |
| 49 | return yield if $DEBUG |
| 50 | pid = Process.fork{ |
| 51 | Process.setsid |
| 52 | Dir.chdir(RAILS_ROOT) |
| 53 | trap("SIGINT"){ exit! 0 } |
| 54 | trap("SIGTERM"){ exit! 0 } |
| 55 | trap("SIGHUP"){ restart_test_server } |
| 56 | File.open("/dev/null"){|f| |
| 57 | STDERR.reopen f |
| 58 | STDIN.reopen f |
| 59 | STDOUT.reopen f |
| 60 | } |
| 61 | yield |
| 62 | } |
| 63 | puts "spec_server launched. (PID: %d)" % pid |
| 64 | File.open(pid_file,"w"){|f| f.puts pid } if pid_file |
| 65 | exit! 0 |
| 66 | end |
| 67 | |
| 68 | options = Hash.new |
| 69 | opts = OptionParser.new |
| 70 | opts.on("-d", "--daemon"){|v| options[:daemon] = true } |
| 71 | opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v } |
| 72 | opts.parse!(ARGV) |
| 73 | |
| 74 | puts "Ready" |
| 75 | exec_server = lambda { |
| 76 | trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2") |
| 77 | DRb.start_service("druby://localhost:8989", Spec::Runner::RailsSpecServer.new) |
| 78 | DRb.thread.join |
| 79 | } |
| 80 | |
| 81 | if options[:daemon] |
| 82 | daemonize(options[:pid], &exec_server) |
| 83 | else |
| 84 | exec_server.call |
| 85 | end |
| 86 | |
| toggle raw diff |
--- /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
+ |
| |   |
| 1 | # This file is copied to ~/spec when you run 'ruby script/generate rspec' |
| 2 | # from the project root directory. |
| 3 | ENV["RAILS_ENV"] = "test" |
| 4 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") |
| 5 | require 'spec/rails' |
| 6 | |
| 7 | Spec::Runner.configure do |config| |
| 8 | config.use_transactional_fixtures = true |
| 9 | config.use_instantiated_fixtures = false |
| 10 | config.fixture_path = RAILS_ROOT + '/spec/fixtures' |
| 11 | |
| 12 | # You can declare fixtures for each behaviour like this: |
| 13 | # describe "...." do |
| 14 | # fixtures :table_a, :table_b |
| 15 | # |
| 16 | # Alternatively, if you prefer to declare them only once, you can |
| 17 | # do so here, like so ... |
| 18 | # |
| 19 | # config.global_fixtures = :table_a, :table_b |
| 20 | # |
| 21 | # If you declare global fixtures, be aware that they will be declared |
| 22 | # for all of your examples, even those that don't use them. |
| 23 | end |
| toggle raw diff |
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,23 @@
+# This file is copied to ~/spec when you run 'ruby script/generate rspec'
+# from the project root directory.
+ENV["RAILS_ENV"] = "test"
+require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
+require 'spec/rails'
+
+Spec::Runner.configure do |config|
+ config.use_transactional_fixtures = true
+ config.use_instantiated_fixtures = false
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures'
+
+ # You can declare fixtures for each behaviour like this:
+ # describe "...." do
+ # fixtures :table_a, :table_b
+ #
+ # Alternatively, if you prefer to declare them only once, you can
+ # do so here, like so ...
+ #
+ # config.global_fixtures = :table_a, :table_b
+ #
+ # If you declare global fixtures, be aware that they will be declared
+ # for all of your examples, even those that don't use them.
+end |