Sha256: bfa9aa6b2105814492810d9746a6bc8ecc42d66f6bb8f5402040eb3e0f73e9a9

Contents?: true

Size: 672 Bytes

Versions: 3

Compression:

Stored size: 672 Bytes

Contents

require 'mspec/guards/guard'

class Object
  def env
    env = ""
    if PlatformGuard.windows?
      env = Hash[*`cmd.exe /C set`.split("\n").map { |e| e.split("=", 2) }.flatten]
    else
      env = Hash[*`env`.split("\n").map { |e| e.split("=", 2) }.flatten]
    end
    env
  end

  def windows_env_echo(var)
    `cmd.exe /C ECHO %#{var}%`.strip
  end  

  def username
    user = ""
    if PlatformGuard.windows?
      user = windows_env_echo('USERNAME')
    else
      user = `whoami`.strip
    end
    user
  end

  def home_directory
    return ENV['HOME'] unless PlatformGuard.windows?
    windows_env_echo('HOMEDRIVE') + windows_env_echo('HOMEPATH')
  end  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mspec-1.5.17 lib/mspec/helpers/environment.rb
mspec-1.5.16 lib/mspec/helpers/environment.rb
mspec-1.5.15 lib/mspec/helpers/environment.rb