将完全字符串与Serverspec(rspec)匹配

时间:2014-08-15 00:51:41

标签: ruby windows rspec chef

我想提出一个失败的测试,除非字符串完全匹配。

导致失败的输出

PS C:\Users\vagrant> auditpol.exe /get /subcategory:'User Account Management'
System audit policy
Category/Subcategory                      Setting
Account Management
  User Account Management                 Success and Failure

应该导致成功的输出:

PS C:\Users\vagrant> auditpol.exe /get /subcategory:'User Account Management'
System audit policy
Category/Subcategory                      Setting
Account Management
  User Account Management                 Success

以下测试的各种排列经过了数小时的谷歌搜索和实验

describe command("auditpol.exe /get /subcategory:'User Account Management'") do 
  its(:stdout){should match(/User Account Management                 Success/)}
end

最有希望的测试就是这个,但是它需要整个输出的精确文字匹配,而不仅仅是所讨论的字符串:

describe command("auditpol.exe /get /subcategory:'User Account Management'") do 
  its(:stdout){should eq(/User Account Management                 Success/)}
end

由于

1 个答案:

答案 0 :(得分:1)

尝试使用$ -sign。

describe command("auditpol.exe /get /subcategory:'User Account Management'") do 
  its(:stdout){should match(/User Account Management                 Success$/)}
end

来源: http://www.regular-expressions.info/anchors.html 还有更多