Commandクラスにby_user
メソッドを追加してみる.
module Serverspec
module Type
class Command
def by_user(user)
self.class.new("su -l '#{user}' -c '#{@name}'")
end
end
end
end
特定ユーザーでログイン後のコマンド実行がテストできる.
describe command('echo $HOME').by_user("www") do
it { should return_stdout "/home/www" }
end
ダブルクォートのクォーテーションはうまく行くが、
describe command('echo "a b c"').by_user("www") do
it { should return_stdout "a b c" }
end
シングルクォートのクォーテーションはうまく出来ない.
describe command("echo 'a b c'").by_user("www") do
it { should return_stdout "a b c" }
end
メッセージは以下. 変数展開ががが...
1) Command "su -l 'www' -c 'echo 'a b c''"
Failure/Error: it { should return_stdout "a b c" }
sudo su -l 'www' -c 'echo 'a b c''
a