chef-boneyard/minitest-chef-handler

test file resource with only_if context

Closed this issue · 1 comments

Hi guys,

I can't get through the following test for a File resource using only_if with File.exists?.

Recipe Code

file '/etc/something' do
  action :delete
  only_if { ::File.exists? '/etc/something_else' }
end

Spec

before {
    ::File.should_receive(:exists?).and_return(true)  # Very bad mocking, and not working
    chefrun.converge('cookbook::recipe')
}
...
  context '/etc/something_else exists' do
     it 'removes /etc/something file' do
       expect(chefrun).to delete_file('/etc/something')
     end
  end

I don't know how to make this test case pass, as no matter how I mock the File::exists? method it breaks the whole test suite or brake the test case.

Please help, thank you in advance.

posted in wrong repo, sorry guys