For example, to check that a directory has been created with the user "nobody" I can use either of two methods:
"Assert that a directory was createed with predicate matchers"
expect(chef_run).to create_directory('/tmp').with_user('nobody')
"Assert that a directory was createed with attributes"
expect(chef_run).to create_directory('/tmp').with(user: 'nobody')
There is a third method using regexs but I'm not concerned with that method.
How do I go about deciding which method to use to assert that the directory was created and is owned by the correct user?
There is no difference: 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($1.to_sym => args.first)
self
else
super
end
end
The with(user: whatever)
syntax is by far more common but it's up to you and your personal style.