Sha256: 5189ad115fdd47410a93509baa08554d07827e6a54300119ca7818d94a7c24ab

Contents?: true

Size: 814 Bytes

Versions: 7

Compression:

Stored size: 814 Bytes

Contents

require 'tempfile'
module CommandLine
  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.seconds) { 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

7 entries across 7 versions & 2 rubygems

Version Path
mirage-3.0.10 features/support/command_line.rb
mirage-3.0.9 features/support/command_line.rb
mirage-on-thin-3.0.8 features/support/command_line.rb
mirage-3.0.8 features/support/command_line.rb
mirage-3.0.7 features/support/command_line.rb
mirage-3.0.6 features/support/command_line.rb
mirage-3.0.5 features/support/command_line.rb