Skip to content

Instantly share code, notes, and snippets.

@deg84
Forked from kozy4324/ext_command.md
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deg84/9743134 to your computer and use it in GitHub Desktop.
Save deg84/9743134 to your computer and use it in GitHub Desktop.
serverspecでユーザーを指定してコマンドを実行させる拡張

Commandクラスにby_userメソッドを追加する。

module Serverspec
  module Type
    class Command
      def by_user(user)
        self.class.new("su -l #{user.shellescape} -c #{@name.shellescape}")
      end
    end
  end
end
require "type/command"

特定ユーザーでログイン後のコマンド実行がテストできる.

describe command('echo $HOME').by_user("www") do
  it { should return_stdout "/home/www" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment