Permalink
Browse files

made the --drb option wait for the spork servers to start before runn…

…ing tests, and throw a more helpful error on failure
  • Loading branch information...
1 parent 287600d commit 81b0edb5890d69aab76b2afd8e25c8f60a71a101 @woahdae woahdae committed Oct 20, 2009
Showing with 73 additions and 19 deletions.
  1. +1 −1 lib/rspactor/inspector.rb
  2. +19 −5 lib/rspactor/interactor.rb
  3. +2 −2 lib/rspactor/runner.rb
  4. +50 −10 lib/rspactor/spork.rb
  5. +1 −1 spec/inspector_spec.rb
@@ -69,7 +69,7 @@ def translate(file)
when 'config/database.yml', 'db/schema.rb', 'spec/factories.rb'
candidates << 'models'
when 'config/boot.rb', 'config/environment.rb', %r:^config/environments/:, %r:^config/initializers/:, %r:^vendor/:, 'spec/spec_helper.rb'
- Spork.reload if runner.options[:spork]
+ runner.spork.reload if runner.spork
Celerity.restart if runner.options[:celerity]
candidates << 'spec'
when %r:^config/:
View
@@ -10,12 +10,26 @@ def initialize(runner)
ticker
end
- def self.ticker_msg(msg, seconds_to_wait = 3)
+ def self.ticker_msg(msg, seconds_to_wait = 3, &block)
$stdout.print msg
- seconds_to_wait.times do
- $stdout.print('.')
- $stdout.flush
- sleep 1
+ if block
+ @yielding_ticker = true
+ Thread.new do
+ loop do
+ $stdout.print('.') if @yielding_ticker == true
+ $stdout.flush
+ sleep 1.0
+ end
+ end
+
+ yield
+ @yielding_ticker = false
+ else
+ seconds_to_wait.times do
+ $stdout.print('.')
+ $stdout.flush
+ sleep 1
+ end
end
$stdout.puts "\n"
end
View
@@ -7,7 +7,7 @@ def self.start(options = {})
new(run_in, options).start
end
- attr_reader :dir, :options, :inspector, :interactor
+ attr_reader :dir, :options, :inspector, :interactor, :spork
def initialize(dir, options = {})
@dir = dir
@@ -18,7 +18,7 @@ def initialize(dir, options = {})
def start
load_dotfile
puts "** RSpactor, now watching at '#{dir}'"
- Spork.start if options[:spork]
+ (@spork = Spork.new(self)) && @spork.start if options[:spork]
Celerity.start(dir) if options[:celerity]
start_interactor
start_listener
View
@@ -1,25 +1,65 @@
require 'rspactor'
+require 'socket'
module RSpactor
class Spork
+ RSPEC_PORT = 8989
+ CUCUMBER_PORT = 8990
- def self.start
- kill_and_launch
- Interactor.ticker_msg "** Launching Spork for rspec & cucumber"
+ attr_accessor :use_cucumber
+
+ def initialize(runner)
+ @use_cucumber = File.exist?(File.join(runner.dir, 'features'))
+ end
+
+ def start
+ execute(:start)
end
- def self.reload
- kill_and_launch
- Interactor.ticker_msg "** Reloading Spork for rspec & cucumber"
+ def reload
+ execute(:reload)
end
private
+
+ def execute(start_or_reload)
+ action_message = (start_or_reload == :start) ? "Starting" : "Reloading"
+ message = "** #{action_message} Spork for rspec"
+ message += " & cucumber" if use_cucumber
+ kill_and_launch(message)
+ end
- def self.kill_and_launch
- system("kill $(ps aux | awk '/spork/&&!/awk/{print $2;}') >/dev/null 2>&1")
- system("spork >/dev/null 2>&1 < /dev/null &")
- system("spork cu >/dev/null 2>&1 < /dev/null &")
+ def kill_and_launch(message)
+ Interactor.ticker_msg message do
+
+ system("kill $(ps aux | awk '/spork/&&!/awk/{print $2;}') >/dev/null 2>&1")
+
+ system("spork >/dev/null 2>&1 < /dev/null &")
+ wait_for('RSpec', RSPEC_PORT)
+
+ if use_cucumber
+ system("spork cu >/dev/null 2>&1 < /dev/null &")
+ wait_for('Cucumber', CUCUMBER_PORT)
+ end
+
+ end
+ end
+
+ def wait_for(sporker, port)
+ 15.times do
+ begin
+ TCPSocket.new('localhost', port).close
+ rescue Errno::ECONNREFUSED
+ sleep(1)
+ next
+ end
+
+ return true
+ end
+
+ raise "could not load spork for #{sporker}; make sure you can use it manually first"
end
end
+
end
View
@@ -3,7 +3,7 @@
describe RSpactor::Inspector do
before(:all) do
options = { :view => true }
- @inspector = described_class.new(mock('Runner', :dir => '/project', :options => options))
+ @inspector = described_class.new(mock('Runner', :dir => '/project', :options => options, :spork => false))
end
def translate(file)

0 comments on commit 81b0edb

Please sign in to comment.