Skip to content

Instantly share code, notes, and snippets.

@sunaku
Created November 9, 2011 18:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunaku/1352391 to your computer and use it in GitHub Desktop.
Save sunaku/1352391 to your computer and use it in GitHub Desktop.
Simple script to emulate Spin using TestR.
#!/usr/bin/env ruby
# This script emulates [Spin] using [TestR].
#
# Usage: testr-spin serve [-I<LOAD_PATH>]... <OVERHEAD_FILE>...
# Usage: testr-spin push <TEST_FILE> [<TEST_NAME>]...
#
# [Spin]: https://github.com/jstorimer/spin
# [TestR]: https://github.com/sunaku/testr
require 'json'
FIFO = File.basename(__FILE__) + '.fifo'
# Sends the given message to the Spin server.
def send message
File.pipe? FIFO or fail 'Did you forget to run `testr-spin serve`?'
File.open(FIFO, 'a') do |fifo|
fifo.puts JSON.dump(message)
end
end
case ARGV.shift
when 'serve'
# create named pipe for Spin client to server communication
system 'mkfifo', FIFO or fail 'Could not create named pipe.'
if fork
begin
# continuously pass input from Spin client to server
system "tail -f #{FIFO} | testr-master"
ensure
File.unlink FIFO
end
else
# preload the Rails environment and the given Ruby files
paths = %w[test spec]; files = Dir['{test,spec}/{test,spec}_helper.rb']
ARGV.each {|a| a =~ /^-I/ ? paths.concat($'.split(/:+/)) : files << a }
send [:load, paths, files]
end
when 'push' then
# tell the Spin server to load the given file and
# only run the given tests within that given file
send [:test, ARGV.shift, ARGV]
else
# show usage information for this script
puts File.read(__FILE__).split(/^$/).first
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment