Sha256: 642d6611d9071934cce6fe7571b9c373c2558779fc46068b6d9e138c3d4c40c9

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

module Spec
  extend self

  require 'tempfile'
  require 'fileutils'

  @dirname, @basename = File.split(File.expand_path(__FILE__))

  attr_accessor *%w(
    dirname
    basename
  )

  @specdir = @dirname

  @tmpdir = File.join(@specdir, 'tmp')
  FileUtils.mkdir_p @tmpdir
  at_exit{ FileUtils.rm_rf @tmpdir }

  @libdir = File.join(File.dirname(@dirname), 'lib')
  ENV['RUBYLIB'] = [ @libdir, ENV['RUBYLIB'] ].compact.join(File::PATH_SEPARATOR)
  $LOAD_PATH.unshift @libdir

  @bindir = File.join(File.dirname(@dirname), 'bin')
  ENV['PATH'] = [ @bindir, ENV['PATH'] ].compact.join(File::PATH_SEPARATOR)

  @rails_root = File.join @specdir, 'rails_root'

  %w(
    specdir
    tmpdir 
    libdir
    bindir
    rails_root
  ).each do |dirvar|
    module_eval <<-code
      def #{ dirvar }(*a, &b)
        paths = [a, b && b.call].flatten.compact.map{|path| path.to_s}
        File.join @#{ dirvar }, *paths
      end
    code
  end

  def pid() @pid ||= Process.pid end

  def fu() FileUtils end

  def Spec.tmpfile(*names, &block)
    names.push pid if names.empty?
    path = tmpdir *names
    open(path, 'w') do |fd|
      fd.sync = true
      block ? block.call(fd) : fd
    end
  ensure
    fu.rm_rf path if block
  end

  def runner commands, *argv, &block
    Dir.chdir(Spec.rails_root) do
      runner = Spec.rails_root('script', 'runner')
      Spec.tmpfile do |tmp|
        tmp.puts commands
        systemu "#{ runner } #{ tmp.path.inspect }", *argv, &block
      end
    end
  end

  def scrub dir
    glob = File.join(dir, '*')
    Dir[glob].each{|entry| FileUtils.rm_rf entry}
  end

  require 'rubygems'
  require 'bacon'

  begin
    require 'systemu'
  rescue LoadError
    require libdir('systemu')
  end

  STDOUT.sync = true
  STDERR.sync = true
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
ambethia-bj-1.2.1 spec/helper.rb
vibes-bj-1.2.2 spec/helper.rb
vibes-bj-1.2.1 spec/helper.rb