My requirement is that I need to run a utility that is installed in other user and I have to check the output returned from that session and verify it. Example :
java -version
runs only in that user and not as root). su srijava
, then I do not get the output returned back to the root session and the test fails. su srijava
then my utility will throw an error
that the user is not SriJavaCode with su
:
describe command('su srijava ; cd /app/java; ./java --version') do
its(:stdout) { should contain('1.7') }
end
Code without su
:
describe command('cd /app/java; ./java --version') do
its(:stdout) { should contain('1.7') }
end
describe command("su -c '/app/java/java --version' srijava") do
its(:stdout) { should contain('1.7') }
end
FYI you are using RSpec 2 and soon to be obsolete Serverspec syntax for your matcher. Consider futureproofing it with:
describe command("su -c '/app/java/java --version' srijava") do
its(:stdout) { is_expected.to match(/1\.7/) }
end