| |   |
| 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 | |
| 10 | # This is based on Florian Weber's TDDMate |
| 11 | module Spec |
| 12 | module Runner |
| 13 | class RailsSpecServer |
| 14 | def run(argv, stderr, stdout) |
| 15 | $stdout = stdout |
| 16 | $stderr = stderr |
| 17 | |
| 18 | base = ActiveRecord::Base |
| 19 | def base.clear_reloadable_connections! |
| 20 | active_connections.each do |name, conn| |
| 21 | if conn.requires_reloading? |
| 22 | conn.disconnect! |
| 23 | active_connections.delete(name) |
| 24 | end |
| 25 | end |
| 26 | end |
| 27 | |
| 28 | if ActionController.const_defined?(:Dispatcher) |
| 29 | dispatcher = ::ActionController::Dispatcher.new($stdout) |
| 30 | dispatcher.cleanup_application(true) |
| 31 | elsif ::Dispatcher.respond_to?(:reset_application!) |
| 32 | ::Dispatcher.reset_application! |
| 33 | else |
| 34 | raise "Application reloading failed" |
| 35 | end |
| 36 | ::Dependencies.mechanism = :load |
| 37 | require_dependency('application.rb') unless Object.const_defined?(:ApplicationController) |
| 38 | load File.dirname(__FILE__) + '/../spec/spec_helper.rb' |
| 39 | |
| 40 | ::Spec::Runner::CommandLine.run( |
| 41 | ::Spec::Runner::OptionParser.parse( |
| 42 | argv, |
| 43 | $stderr, |
| 44 | $stdout |
| 45 | ) |
| 46 | ) |
| 47 | end |
| 48 | end |
| 49 | end |
| 50 | end |
| 51 | puts "Loading Rails environment" |
| 52 | |
| 53 | ENV["RAILS_ENV"] = "test" |
| 54 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") |
| 55 | require 'dispatcher' |
| 56 | |
| 57 | def restart_test_server |
| 58 | puts "restarting" |
| 59 | config = ::Config::CONFIG |
| 60 | ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT'] |
| 61 | command_line = [ruby, $0, ARGV].flatten.join(' ') |
| 62 | exec(command_line) |
| 63 | end |
| 64 | |
| 65 | def daemonize(pid_file = nil) |
| 66 | return yield if $DEBUG |
| 67 | pid = Process.fork{ |
| 68 | Process.setsid |
| 69 | Dir.chdir(RAILS_ROOT) |
| 70 | trap("SIGINT"){ exit! 0 } |
| 71 | trap("SIGTERM"){ exit! 0 } |
| 72 | trap("SIGHUP"){ restart_test_server } |
| 73 | File.open("/dev/null"){|f| |
| 74 | STDERR.reopen f |
| 75 | STDIN.reopen f |
| 76 | STDOUT.reopen f |
| 77 | } |
| 78 | yield |
| 79 | } |
| 80 | puts "spec_server launched. (PID: %d)" % pid |
| 81 | File.open(pid_file,"w"){|f| f.puts pid } if pid_file |
| 82 | exit! 0 |
| 83 | end |
| 84 | |
| 85 | options = Hash.new |
| 86 | opts = OptionParser.new |
| 87 | opts.on("-d", "--daemon"){|v| options[:daemon] = true } |
| 88 | opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v } |
| 89 | opts.parse!(ARGV) |
| 90 | |
| 91 | puts "Ready" |
| 92 | exec_server = lambda { |
| 93 | trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2") |
| 94 | DRb.start_service("druby://localhost:8989", Spec::Runner::RailsSpecServer.new) |
| 95 | DRb.thread.join |
| 96 | } |
| 97 | |
| 98 | if options[:daemon] |
| 99 | daemonize(options[:pid], &exec_server) |
| 100 | else |
| 101 | exec_server.call |
| 102 | end |
| toggle raw diff |
--- /dev/null
+++ b/script/spec_server
@@ -0,0 +1,102 @@
+#!/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'
+
+# This is based on Florian Weber's TDDMate
+module Spec
+ module Runner
+ class RailsSpecServer
+ def run(argv, stderr, stdout)
+ $stdout = stdout
+ $stderr = stderr
+
+ base = ActiveRecord::Base
+ def base.clear_reloadable_connections!
+ active_connections.each do |name, conn|
+ if conn.requires_reloading?
+ conn.disconnect!
+ active_connections.delete(name)
+ end
+ end
+ end
+
+ if ActionController.const_defined?(:Dispatcher)
+ dispatcher = ::ActionController::Dispatcher.new($stdout)
+ dispatcher.cleanup_application(true)
+ elsif ::Dispatcher.respond_to?(:reset_application!)
+ ::Dispatcher.reset_application!
+ else
+ raise "Application reloading failed"
+ end
+ ::Dependencies.mechanism = :load
+ require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
+ load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
+
+ ::Spec::Runner::CommandLine.run(
+ ::Spec::Runner::OptionParser.parse(
+ argv,
+ $stderr,
+ $stdout
+ )
+ )
+ 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' |
| 6 | require 'spec/rails' |
| 7 | |
| 8 | Spec::Runner.configure do |config| |
| 9 | # If you're not using ActiveRecord you should remove these |
| 10 | # lines, delete config/database.yml and disable :active_record |
| 11 | # in your config/boot.rb |
| 12 | config.use_transactional_fixtures = true |
| 13 | config.use_instantiated_fixtures = false |
| 14 | config.fixture_path = RAILS_ROOT + '/spec/fixtures/' |
| 15 | |
| 16 | # == Fixtures |
| 17 | # |
| 18 | # You can declare fixtures for each example_group like this: |
| 19 | # describe "...." do |
| 20 | # fixtures :table_a, :table_b |
| 21 | # |
| 22 | # Alternatively, if you prefer to declare them only once, you can |
| 23 | # do so right here. Just uncomment the next line and replace the fixture |
| 24 | # names with your fixtures. |
| 25 | # |
| 26 | # config.global_fixtures = :table_a, :table_b |
| 27 | # |
| 28 | # If you declare global fixtures, be aware that they will be declared |
| 29 | # for all of your examples, even those that don't use them. |
| 30 | # |
| 31 | # == Mock Framework |
| 32 | # |
| 33 | # RSpec uses it's own mocking framework by default. If you prefer to |
| 34 | # use mocha, flexmock or RR, uncomment the appropriate line: |
| 35 | # |
| 36 | # config.mock_with :mocha |
| 37 | # config.mock_with :flexmock |
| 38 | # config.mock_with :rr |
| 39 | end |
| toggle raw diff |
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,39 @@
+# 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'
+require 'spec/rails'
+
+Spec::Runner.configure do |config|
+ # If you're not using ActiveRecord you should remove these
+ # lines, delete config/database.yml and disable :active_record
+ # in your config/boot.rb
+ config.use_transactional_fixtures = true
+ config.use_instantiated_fixtures = false
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
+
+ # == Fixtures
+ #
+ # You can declare fixtures for each example_group like this:
+ # describe "...." do
+ # fixtures :table_a, :table_b
+ #
+ # Alternatively, if you prefer to declare them only once, you can
+ # do so right here. Just uncomment the next line and replace the fixture
+ # names with your fixtures.
+ #
+ # 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.
+ #
+ # == Mock Framework
+ #
+ # RSpec uses it's own mocking framework by default. If you prefer to
+ # use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+end |