rspec - Mocking Files during a ChefSpec run -


i created chef resource 'extends' deploy resource of chef. basic idea check existence of file deploy/crontab similar mechanisms deploy/after_restart.rb in source deployed, , create cronjobs out of it.

while mechanism works should (see https://github.com/fh/easybib-cookbooks/blob/t/cron-tests/easybib/providers/deploy.rb#l11-l14), struggling chefspec based test it. trying create mocks using fakefs - when mock filesystem before chef run, run fails because no cookbooks found, since not exist in mocked filesystem. if dont, mocked file deploy/crontab not found, provider doesnt anything. current approach trigger fakefs.activate! directly before runner.converge(described_recipe) in chef_run.

i love hear recommendations how proper test here: there maybe possiblity enable fakefs directly before deploy-resource-run, or mock filesystem partially?

i had similar problem stubbing file system classes. way have been solving problem follows.

::file.stub(:exists?).with(anything).and_call_original ::file.stub(:exists?).with('/tmp/deploy/crontab').and_return true  open_file = double('file') allow(open_file).to receive(:each_line).and_yield('line1').and_yield('line2')  ::file.stub(:open).and_call_original ::file.stub(:open).with('/tmp/deploy/crontab').and_return open_file 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -