0

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?

user3481957
  • 151
  • 1
  • 1
  • 10

1 Answers1

0

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.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Thanks, I appreciate the link. Although this should be documented one would think. I just assume no one would go through the effort of creating additional variations of syntax if there wasn't any difference in the outcome or side effects. – user3481957 Jul 14 '17 at 20:15
  • I mean 99% of what ChefSpec and RSpec do is syntactic sugar for tasks you can do other ways already so ... yes people do a lot of that. – coderanger Jul 14 '17 at 21:12