chefspec:谓词匹配器和属性之间有什么区别?
chefspec: What is the difference between predicate matchers and attributes?
例如,要检查用户 "nobody" 是否创建了一个目录,我可以使用两个 methods:
"断言目录是使用谓词匹配器创建的"
expect(chef_run).to create_directory('/tmp').with_user('nobody')
"断言创建的目录具有属性"
expect(chef_run).to create_directory('/tmp').with(user: 'nobody')
还有第三种使用正则表达式的方法,但我不关心那个方法。
我如何决定使用哪种方法来断言该目录已创建并归正确的用户所有?
没有区别:https://github.com/chefspec/chefspec/blob/master/lib/chefspec/matchers/resource_matcher.rb#L32-L34
def method_missing(m, *args, &block)
if m.to_s =~ /^with_(.+)$/
with(.to_sym => args.first)
self
else
super
end
end
with(user: whatever)
语法更为常见,但这取决于您和您的个人风格。
例如,要检查用户 "nobody" 是否创建了一个目录,我可以使用两个 methods:
"断言目录是使用谓词匹配器创建的"
expect(chef_run).to create_directory('/tmp').with_user('nobody')
"断言创建的目录具有属性"
expect(chef_run).to create_directory('/tmp').with(user: 'nobody')
还有第三种使用正则表达式的方法,但我不关心那个方法。
我如何决定使用哪种方法来断言该目录已创建并归正确的用户所有?
没有区别:https://github.com/chefspec/chefspec/blob/master/lib/chefspec/matchers/resource_matcher.rb#L32-L34
def method_missing(m, *args, &block)
if m.to_s =~ /^with_(.+)$/
with(.to_sym => args.first)
self
else
super
end
end
with(user: whatever)
语法更为常见,但这取决于您和您的个人风格。