Clean up specs

This commit is contained in:
Fabio Rehm 2013-03-01 23:27:08 -03:00
parent 4a9d74514e
commit 227a598917
2 changed files with 25 additions and 23 deletions

View file

@ -22,7 +22,9 @@ module Vagrant
def create def create
# FIXME: Ruby 1.8 users dont have SecureRandom # FIXME: Ruby 1.8 users dont have SecureRandom
machine_id = SecureRandom.hex(6) machine_id = SecureRandom.hex(6)
log, status = lxc :create, '--template', 'ubuntu-cloud', '--name', machine_id, '--', '-S', '/home/vagrant/.ssh/id_rsa.pub' public_key = Vagrant.source_root.join('../keys/vagrant.pub').expand_path.to_s
log, status = lxc :create, '--template', 'ubuntu-cloud', '--name', machine_id, '--', '-S', public_key
# TODO: Handle errors
machine_id machine_id
end end

View file

@ -30,45 +30,41 @@ describe Vagrant::LXC::Container do
end end
describe 'guard for container state' do describe 'guard for container state' do
let(:last_command) { @last_command }
let(:machine_id) { 'random-machine-id' } let(:machine_id) { 'random-machine-id' }
let(:machine) { fire_double('Vagrant::Machine', id: machine_id) } let(:machine) { fire_double('Vagrant::Machine', id: machine_id) }
before do before do
subject.stub(:lxc) do |*cmds| subject.stub :lxc
@last_command = cmds.join(' ')
mock(exit_code: 0, stdout: '')
end
subject.wait_until :running subject.wait_until :running
end end
it 'runs lxc-wait with the machine id' do it 'runs lxc-wait with the machine id and upcased state' do
last_command.should include "--name #{machine_id}" subject.should have_received(:lxc).with(
end :wait,
'--name', machine_id,
it 'runs lxc-wait with upcased state' do '--state', 'RUNNING'
last_command.should include "--state RUNNING" )
end end
end end
describe 'creation' do describe 'creation' do
let(:last_command) { @last_command } let(:new_machine_id) { 'random-machine-id' }
let(:new_machine_id) { 'random-machine-id' } let(:public_key_path) { Vagrant.source_root.join('..', 'keys', 'vagrant.pub').expand_path.to_s }
before do before do
subject.stub(:lxc) do |*cmds| subject.stub(:lxc)
@last_command = cmds.join(' ')
mock(exit_code: 0, stdout: '')
end
SecureRandom.stub(hex: new_machine_id) SecureRandom.stub(hex: new_machine_id)
subject.create subject.create
end end
it 'calls lxc-create with the right arguments' do it 'calls lxc-create with the right arguments' do
last_command.should =~ /^create/ subject.should have_received(:lxc).with(
last_command.should include "--name #{new_machine_id}" :create,
last_command.should include "--template ubuntu-cloud" '--template', 'ubuntu-cloud',
last_command.should =~ /\-\- \-S (\w|\/|\.)+\/id_rsa\.pub$/ '--name', new_machine_id,
'--',
'-S', public_key_path
)
end end
end end
@ -82,7 +78,11 @@ describe Vagrant::LXC::Container do
end end
it 'calls lxc-start with the right arguments' do it 'calls lxc-start with the right arguments' do
subject.should have_received(:lxc).with(:start, '-d', '--name', machine.id) subject.should have_received(:lxc).with(
:start,
'-d',
'--name', machine.id
)
end end
it 'waits for container state to be RUNNING' do it 'waits for container state to be RUNNING' do