Class: Cmd
- Inherits:
-
Object
- Object
- Cmd
- Defined in:
- lib/resources/command.rb
Overview
Usage: describe command(‘ls -al /’) do
it { should exist }
its(:stdout) { should match /bin/ }
its(:stderr) { should match /No such file or directory/ }
its(:exit_status) { should eq 0 }
end
Direct Known Subclasses
Instance Method Summary collapse
- #exist? ⇒ Boolean
- #exit_status ⇒ Object
-
#initialize(cmd) ⇒ Cmd
constructor
A new instance of Cmd.
- #result ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(cmd) ⇒ Cmd
Returns a new instance of Cmd.
17 18 19 |
# File 'lib/resources/command.rb', line 17 def initialize(cmd) @command = cmd end |
Instance Method Details
#exist? ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/resources/command.rb', line 37 def exist? if inspec.os.linux? res = inspec.backend.run_command("bash -c 'type \"#{@command}\"'") elsif inspec.os.windows? res = inspec.backend.run_command("where.exe \"#{@command}\"") elsif inspec.os.unix? res = inspec.backend.run_command("type \"#{@command}\"") elsif inspec.os[:family].to_s == 'unknown' # silent for mock resources return false else warn "`command(#{@command}).exist?` is not suported on you OS: #{inspec.os[:family]}" return false end res.exit_status.to_i == 0 end |
#exit_status ⇒ Object
33 34 35 |
# File 'lib/resources/command.rb', line 33 def exit_status result.exit_status.to_i end |
#result ⇒ Object
21 22 23 |
# File 'lib/resources/command.rb', line 21 def result @result ||= inspec.backend.run_command(@command) end |
#stderr ⇒ Object
29 30 31 |
# File 'lib/resources/command.rb', line 29 def stderr result.stderr end |
#stdout ⇒ Object
25 26 27 |
# File 'lib/resources/command.rb', line 25 def stdout result.stdout end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/resources/command.rb', line 54 def to_s "Command #{@command}" end |