在ServerPec中的命令资源中使用变量



i在服务器配方中有以下测试 - 哈希只是厨师中描述的整个资源(我希望在某个时候可以管道)

# 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-dom1s37374') do
    its(:stdout) { should include "FullControl" }
end

我遇到的问题是在命令资源中获取变量 - 我是Ruby的新手,并且想知道我是否缺少某些东西。

我希望命令资源调用以接受变量而不是被硬编码。

,例如

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

我设法在:stdout测试中使用了变量,但无法在命令行中使用。

任何帮助都非常感谢

您可以在serverVec测试中使用hash的变量(使用现代RSPEC 3):

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

"#{}"语法将在字符串中插值您的变量,而hash[key]语法将从您的哈希(Hash)中获取值。

您还可以迭代您的哈希(Hash)执行更多类似的检查:

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

最新更新