Sha256: 715630fc512061d5fc18e32c692f2291c23f29514e508c823643beb97d6799ba
Contents?: true
Size: 1.3 KB
Versions: 4
Compression:
Stored size: 1.3 KB
Contents
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'rspec' # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} RSpec.configure do |config| end require 'daemon' require 'RMagick' def gem_dir Pathname.new(__FILE__).dirname + '..' end def spec_dir gem_dir + 'spec' end def identify(data) image = Magick::Image.from_blob(data).first out = Struct.new(:format, :width, :height).new(image.format, image.columns, image.rows) image.destroy! out end def get(url) HTTPClient.new.get_content(url) end def start_server(cmd, pid_file, log_file, test_url) stop_server(pid_file) fork do Daemon.daemonize(pid_file, log_file) exec(cmd) end Process.wait ppid = Process.pid at_exit do stop_server(pid_file) if Process.pid == ppid end Timeout.timeout(10) do begin get test_url rescue Errno::ECONNREFUSED sleep 0.1 retry end end end def stop_server(pid_file) pid_file = Pathname.new(pid_file) return unless pid_file.exist? pid = pid_file.read.strip.to_i Timeout.timeout(20) do begin loop do Process.kill("TERM", pid) sleep 0.1 end rescue Errno::ESRCH pid_file.unlink end end end
Version data entries
4 entries across 4 versions & 1 rubygems