Skip to content

Instantly share code, notes, and snippets.

@sunaku sunaku/testr-spin
Created Nov 9, 2011

Embed
What would you like to do?
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
You can’t perform that action at this time.