Sha256: 50c1872365ea9b8c1157918c1a749226d8b332b6d77de58ee183fd135ebdda6c

Contents?: true

Size: 862 Bytes

Versions: 3

Compression:

Stored size: 862 Bytes

Contents

require 'tempfile'
require 'wait_methods'

module CommandLine
  include Mirage::WaitMethods

  def run command
    output = Tempfile.new("child")
    Dir.chdir SCRATCH do
      process = ChildProcess.build(*("#{command}".split(' ')))
      process.detach
      process.io.stdout = output
      process.io.stderr = output
      process.start
      wait_until(:timeout_after => 30) { process.exited? }
    end
    File.read(output.path)
  end

  def normalise text
    text.gsub(/[\n]/, ' ').gsub(/\s+/, ' ').strip
  end

  def write_to_file file_path, content
    file_path = "#{SCRATCH}/#{file_path}" unless file_path =~ /^\//

    FileUtils.rm_rf(file_path) if File.exists?(file_path)
    FileUtils.mkdir_p(File.dirname(file_path))

    File.open("#{file_path}", 'w') do |file|
      file.write(content)
    end
  end
end

World CommandLine
include CommandLine

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mirage-3.0.13 features/support/command_line.rb
mirage-3.0.12 features/support/command_line.rb
mirage-3.0.11 features/support/command_line.rb