2017-02-20 12 views
2

のコマンドリソースに変数を使用して - ハッシュは、それがシェフに記載されているように、単に全体の資源である私はserverspecレシピで次のテストを持っているserverspec

(私はの中でいくつかの点でパイプに期待しています)
# Test Folder Permissons 
# hash taken from attributes 
share = { 
    "name" => "example", 
    "sharepath" => "d:/example", 
    "fullshareaccess" => "everyone", 
    "ntfsfullcontrol" => "u-dom1/s37374", 
    "ntfsmodifyaccess" => "", 
    "ntfsreadaccess" => "everyone" 
    } 

# Explicitly test individual permissions (base on NTFSSecurity module) 
describe command ('get-ntfsaccess d:/example -account u-dom1\s37374') do 
    its(:stdout) { should include "FullControl" } 
end 

私が抱えている問題は、コマンドリソースに変数を取得していることです。私はRubyを初めて使用していて、何か不足していると思っています。

ハードコードされているのではなく、変数を受け入れるコマンドリソースコールが必要です。

describe command ('get-ntfsaccess d:/example -account "#{ntfsfullcontrol}"') do 
    its(:stdout) { should include "FullControl" } 
end 

私は:stdoutテストで変数を使用するために管理しているが、それらは、コマンドラインで働いて得ることができません。

ずっとあなたが(現代のRSpecの3を使用して)このようなServerspecテストの内側にあなたのハッシュから変数を使用することができます

答えて

1

を感謝任意のヘルプ:

describe command ("get-ntfsaccess #{share['sharepath']} -account #{share['ntfsfullcontrol']") do 
    its(:stdout) { is_expected.to include "FullControl" } 
end 

"#{}"構文は、文字列内のあなたの変数を補間しますhash[key]構文はハッシュから値を取得します。

ます。また、このようなより多くのチェックを実行するために、あなたのハッシュを反復することができます

share.each |key, value| do 
    describe command("test with #{key} #{value}") do 
    # first loop: test with name example 
    its(:stdout) { is_expected.to match(/foo/) } 
    end 
end 
+0

御馳走を働いたおかげでマット - 私はあなたがきれいにクリアされているいくつかの構文上の問題があった - 今、シェフからでハッシュをピッピングへ。 –

関連する問題