Module: PSWindows::File

Includes:
Beaker::CommandFactory
Included in:
Host
Defined in:
lib/beaker/host/pswindows/file.rb

Instance Attribute Summary

Attributes included from Beaker::CommandFactory

#assertions

Instance Method Summary collapse

Methods included from Beaker::CommandFactory

#execute, #fail_test

Instance Method Details

#cat(path) ⇒ Object



27
28
29
# File 'lib/beaker/host/pswindows/file.rb', line 27

def cat(path)
  exec(powershell("type #{path}")).stdout
end

#file_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/beaker/host/pswindows/file.rb', line 31

def file_exist?(path)
  result = exec(Beaker::Command.new("if exist #{path} echo true"), accept_all_exit_codes: true)
  result.stdout.strip == 'true'
end

#path_split(paths) ⇒ Object



23
24
25
# File 'lib/beaker/host/pswindows/file.rb', line 23

def path_split(paths)
  paths.split(';')
end

#tmpdir(name = '') ⇒ Object



15
16
17
18
19
20
21
# File 'lib/beaker/host/pswindows/file.rb', line 15

def tmpdir(name = '')
  tmp_path = exec(powershell('[System.IO.Path]::GetTempPath()')).stdout.chomp

  name = exec(powershell('[System.IO.Path]::GetRandomFileName()')).stdout.chomp if name == ''
  exec(powershell("New-Item -Path '#{tmp_path}' -Force -Name '#{name}' -ItemType 'directory'"))
  File.join(tmp_path, name)
end

#tmpfile(_name = '', extension = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/beaker/host/pswindows/file.rb', line 4

def tmpfile(_name = '', extension = nil)
  if extension
    # TODO: I do not have access to Windows, but the internet suggests this
    # $newname = [System.IO.Path]::ChangeExtension($filename, "#{extension}") ; MoveItem $filename $newname
    raise NotImplementedError, 'Passing an extension is not implemented'
  end

  result = exec(powershell('[System.IO.Path]::GetTempFileName()'))
  result.stdout.chomp
end