Browse files

Allows multiple files to be pushed at the same time

  • Loading branch information...
jstorimer committed Nov 2, 2011
1 parent f4f820f commit fb9f040dd2b0553808138ecff51bba85effa8021
Showing with 20 additions and 12 deletions.
  1. +6 −0
  2. +14 −12 bin/spin
@@ -29,6 +29,12 @@ As soon as the server is running it will be ready to accept from clients. You ca
spin push test/unit/product_test.rb
+Or push multiple files to be loaded at once:
+``` bash
+spin push test/unit/product_test.rb test/unit/shop_test.rb test/unit/cart_test.rb
### With Kicker
As mentioned, this tool works best with an autotest(ish) workflow. I haven't actually used with with `autotest` itself, but it works great with [kicker]( Here's the suggested workflow for a Rails app:
@@ -17,7 +17,7 @@ require 'benchmark'
def usage(stream = $stderr)
stream.puts <<-USAGE
Usage: spin serve
- spin push <file>...
+ spin push <file> <file>...
Spin preloads your Rails environment to speed up your autotest(ish) workflow.
@@ -66,30 +66,31 @@ def serve
loop do
- # Since `spin push` reconnects each time it has a new file for us we just
+ # Since `spin push` reconnects each time it has new files for us we just
# need to accept(2) connections from it.
conn = socket.accept
- # This should be a relative path to a file.
- file = conn.gets.chomp
+ # This should be a list of relative paths to files.
+ files = conn.gets.chomp
+ files = files.split(File::PATH_SEPARATOR)
# We fork(2) before loading the file so that our pristine preloaded
# environment is untouched. The child process will load whatever code it
# needs to, then it exits and we're back to the baseline preloaded app.
fork do
- puts "Loading #{file}"
+ puts "Loading #{files.inspect}"
# Unfortunately rspec's interface isn't as simple as just requiring the
# test file that you want to run (suddenly test/unit seems like the less
# crazy one!).
if defined?(RSpec)
# We pretend the filepath came in as an argument and duplicate the
# behaviour of the `rspec` binary.
- ARGV.push file
+ ARGV.push files
require 'rspec/autorun'
# We require the full path of the file here in the child process.
- require File.expand_path file
+ files.each { |f| require File.expand_path f }
@@ -113,11 +114,12 @@ def push
# We reject anything in ARGV that isn't a file that exists. This takes
# care of scripts that specify files like `spin push -r file.rb`. The `-r`
# bit will just be ignored.
- { |f| File.exist?(f) }.each do |f|
- puts "Spinning up #{f}"
- # We put the filename on the socket for the server to read and then load.
- socket.puts f
- end
+ #
+ # We build a string like `file1.rb:file2.rb` and pass it up to the server.
+ f = { |f| File.exist?(f) }.join(File::PATH_SEPARATOR)
+ puts "Spinning up #{f}"
+ # We put the filenames on the socket for the server to read and then load.
+ socket.puts f
rescue Errno::ECONNREFUSED
abort "Connection was refused. Have you started up `spin serve` yet?"

0 comments on commit fb9f040

Please sign in to comment.