使用 serverspec 检查不存在的文件
Checking non existing file with serverspec
我刚开始使用 serverspec 编写测试。我真的很喜欢它,因为它清晰而快速。但是我发现了一个问题。
可以使用文件类型检查文件是否不存在吗?我尝试在各处添加 not
和 !
,但似乎不起作用。
目前我可以使用以下方法实现预期的行为:
describe command('ls /etc/myfile') do
its(:stderr) { should match /No such file or directory/ }
end
但我想用一种方法使它更干净:
describe file ('/etc/myfile') do
it { not should be file }
end
有人知道吗?谢谢
'should_not'期望就是您要找的:
describe file ('/etc/myfile') do
it { should_not be_a_file }
end
我刚开始使用 serverspec 编写测试。我真的很喜欢它,因为它清晰而快速。但是我发现了一个问题。
可以使用文件类型检查文件是否不存在吗?我尝试在各处添加 not
和 !
,但似乎不起作用。
目前我可以使用以下方法实现预期的行为:
describe command('ls /etc/myfile') do
its(:stderr) { should match /No such file or directory/ }
end
但我想用一种方法使它更干净:
describe file ('/etc/myfile') do
it { not should be file }
end
有人知道吗?谢谢
'should_not'期望就是您要找的:
describe file ('/etc/myfile') do
it { should_not be_a_file }
end