rubychef-infrachefspec

Chef | Writting a Spec for Directory Rights assignment


I'm new to Chef and ruby and working through a training project and I've gotten hung up on something which is probably very simple but I have exhausted my ability to google search and/or beat into submission. I have the following resource...

directory node['tcbuildagent']['toolsfolderpath'] do
  action :create
  owner 'BUILTIN\\Administrators'
  group 'BUILTIN\\Administrators'
  rights :read_execute, 'Everyone', applies_to_children: true
end

...and my spec looks like...

  it 'creates creates tools directory' do
    expect(chef_run).to create_directory('c:\fakepathone').with(
      owner: 'BUILTIN\\Administrators',
      group: 'BUILTIN\\Administrators',
      rights: [{ permissions: 'read_execute', principals: 'Everyone', applies_to_children: true }]
    )

end

...for the life of me I cannot get the test for rights portion to work. My most recent error is...

  1) tcbuildagent::default creates creates tools directory
     Failure/Error:
       expect(chef_run).to create_directory('c:\fakepathone').with(
         owner: 'BUILTIN\\Administrators',
         group: 'BUILTIN\\Administrators',
         rights: [{ permissions: 'read_execute', principals: 'Everyone', applies_to_children: true }]
       )

       expected "directory[c:\fakepathone]" to have parameters:

         rights [{:permissions=>"read_execute", :principals=>"Everyone", :applies_to_children=>true}], was [{:permissions=>:read_execute, :principals=>"Everyone", :applies_to_children=>true}]
       Diff:
       @@ -1,4 +1,4 @@
       -[{:permissions=>"read_execute",
       +[{:permissions=>:read_execute,
          :principals=>"Everyone",
          :applies_to_children=>true}]
     # ./spec/unit/recipes/default_spec.rb:19:in `block (2 levels) in <top (required)>'

...but I have seen many other errors along the way.

What am I missing here? Thanks.


Solution

  • You have 'read_execute' as a string, it needs to be :read_execute (i.e. a symbol).

    'foo' != :foo :-)