I have a chef cookbook which copies the ubutunu user's (default user of the amazon AMI am using) authorized keys file to a newly created user.
ubuntu_public_key_file = "/home/ubuntu/.ssh/authorized_keys"
file "#{new_user_homedir}/.ssh/authorized_keys" do
owner new_user
group new_user_group
mode "0600"
content IO.read(ubuntu_public_key_file)
end
Am trying out chefspec and I want to test this out. I want to mock the existence of ubuntu_public_key_file and its contents. Any feedback on this is appreciated!
You use RSpec stubs:
describe 'cookbook::recipe' do
let(:content) do
"CUSTOM SSH KEY CONTENT HERE"
end
before do
IO.stub(:read).with('/home/ubuntu/.ssh/authorized_keys').and_return(content)
end
end