Sha256: c64bd1c8737ac663059943f793288cc99873983b554910afe5e8b6c641280acb

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'
require 'foreman/process'
require 'ostruct'
require 'timeout'
require 'tmpdir'

describe Foreman::Process do

  def run(process, options={})
    rd, wr = IO.method(:pipe).arity.zero? ? IO.pipe : IO.pipe("BINARY")
    process.run(options.merge(:output => wr))
    rd.gets
  end

  describe "#run" do

    it "runs the process" do
      process = Foreman::Process.new(resource_path("bin/test"))
      run(process).should == "testing\n"
    end

    it "can set environment" do
      process = Foreman::Process.new(resource_path("bin/env FOO"), :env => { "FOO" => "bar" })
      run(process).should == "bar\n"
    end

    it "can set per-run environment" do
      process = Foreman::Process.new(resource_path("bin/env FOO"))
      run(process, :env => { "FOO" => "bar "}).should == "bar\n"
    end

    it "can handle env vars in the command" do
      process = Foreman::Process.new(resource_path("bin/echo $FOO"), :env => { "FOO" => "bar" })
      run(process).should == "bar\n"
    end

    it "can handle per-run env vars in the command" do
      process = Foreman::Process.new(resource_path("bin/echo $FOO"))
      run(process, :env => { "FOO" => "bar" }).should == "bar\n"
    end

    it "should output utf8 properly" do
      process = Foreman::Process.new(resource_path("bin/utf8"))
      run(process).should == "\xFF\x03\n".force_encoding('binary')
    end
  end

end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/foreman-0.63.0/spec/foreman/process_spec.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/foreman-0.63.0/spec/foreman/process_spec.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/foreman-0.63.0/spec/foreman/process_spec.rb
foreman-0.63.0-mingw32 spec/foreman/process_spec.rb
foreman-0.63.0-java spec/foreman/process_spec.rb
foreman-0.63.0 spec/foreman/process_spec.rb
foreman-0.62.0-mingw32 spec/foreman/process_spec.rb
foreman-0.62.0-java spec/foreman/process_spec.rb
foreman-0.62.0 spec/foreman/process_spec.rb