LoginSignup
10
10

More than 5 years have passed since last update.

serverspecでユーザーを指定してコマンドを実行

Posted at

はじめに

serverspecでユーザーを一時的に変更してコマンドを実行する方法を解説します。

spec_helper.rb

次のメソッドを追記します。

def user_command(user, cmd)
  command("su -l #{user} -c '#{cmd}'")
end

使い方

  • rbenv_spec.rb
require 'spec_helper'

describe user_command(:alice, 'rbenv versions') do
  its(:stdout) { should match /system/ }
  its(:stdout) { should match /\* 2.0.0-p353/ }
  its(:stdout) { should match /2.1.3/ }
end
10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10