vagrant 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/Gemfile +4 -4
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/bin/vagrant +5 -13
  5. data/config/default.rb +1 -0
  6. data/keys/README.md +8 -1
  7. data/keys/vagrant.ppk +26 -0
  8. data/lib/vagrant.rb +3 -3
  9. data/lib/vagrant/actions/base.rb +15 -4
  10. data/lib/vagrant/actions/box/add.rb +1 -1
  11. data/lib/vagrant/actions/box/download.rb +72 -66
  12. data/lib/vagrant/actions/box/unpackage.rb +1 -4
  13. data/lib/vagrant/actions/runner.rb +1 -1
  14. data/lib/vagrant/actions/vm/boot.rb +5 -7
  15. data/lib/vagrant/actions/vm/customize.rb +2 -2
  16. data/lib/vagrant/actions/vm/destroy.rb +2 -2
  17. data/lib/vagrant/actions/vm/down.rb +7 -0
  18. data/lib/vagrant/actions/vm/export.rb +10 -4
  19. data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
  20. data/lib/vagrant/actions/vm/halt.rb +5 -3
  21. data/lib/vagrant/actions/vm/import.rb +10 -3
  22. data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
  23. data/lib/vagrant/actions/vm/package.rb +33 -10
  24. data/lib/vagrant/actions/vm/provision.rb +4 -4
  25. data/lib/vagrant/actions/vm/reload.rb +1 -1
  26. data/lib/vagrant/actions/vm/resume.rb +1 -1
  27. data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
  28. data/lib/vagrant/actions/vm/start.rb +3 -2
  29. data/lib/vagrant/actions/vm/suspend.rb +2 -2
  30. data/lib/vagrant/actions/vm/up.rb +7 -17
  31. data/lib/vagrant/active_list.rb +52 -45
  32. data/lib/vagrant/box.rb +18 -11
  33. data/lib/vagrant/busy.rb +7 -0
  34. data/lib/vagrant/command.rb +27 -0
  35. data/lib/vagrant/commands/base.rb +163 -0
  36. data/lib/vagrant/commands/box.rb +16 -0
  37. data/lib/vagrant/commands/box/add.rb +24 -0
  38. data/lib/vagrant/commands/box/list.rb +30 -0
  39. data/lib/vagrant/commands/box/remove.rb +31 -0
  40. data/lib/vagrant/commands/destroy.rb +23 -0
  41. data/lib/vagrant/commands/down.rb +16 -0
  42. data/lib/vagrant/commands/halt.rb +23 -0
  43. data/lib/vagrant/commands/init.rb +32 -0
  44. data/lib/vagrant/commands/package.rb +46 -0
  45. data/lib/vagrant/commands/reload.rb +22 -0
  46. data/lib/vagrant/commands/resume.rb +22 -0
  47. data/lib/vagrant/commands/ssh.rb +22 -0
  48. data/lib/vagrant/commands/ssh_config.rb +30 -0
  49. data/lib/vagrant/commands/status.rb +58 -0
  50. data/lib/vagrant/commands/suspend.rb +23 -0
  51. data/lib/vagrant/commands/up.rb +26 -0
  52. data/lib/vagrant/config.rb +21 -11
  53. data/lib/vagrant/downloaders/file.rb +5 -5
  54. data/lib/vagrant/downloaders/http.rb +10 -15
  55. data/lib/vagrant/environment.rb +259 -0
  56. data/lib/vagrant/provisioners/base.rb +7 -0
  57. data/lib/vagrant/provisioners/chef.rb +24 -9
  58. data/lib/vagrant/provisioners/chef_server.rb +23 -48
  59. data/lib/vagrant/provisioners/chef_solo.rb +48 -22
  60. data/lib/vagrant/ssh.rb +95 -46
  61. data/lib/vagrant/util.rb +2 -2
  62. data/lib/vagrant/util/errors.rb +36 -0
  63. data/lib/vagrant/util/platform.rb +12 -0
  64. data/lib/vagrant/util/progress_meter.rb +33 -0
  65. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  66. data/lib/vagrant/util/template_renderer.rb +83 -0
  67. data/lib/vagrant/vm.rb +1 -0
  68. data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
  69. data/templates/chef_server_client.erb +16 -0
  70. data/templates/chef_solo_solo.erb +4 -0
  71. data/templates/errors.yml +157 -0
  72. data/templates/package_Vagrantfile.erb +11 -0
  73. data/templates/ssh_config.erb +7 -0
  74. data/test/test_helper.rb +12 -15
  75. data/test/vagrant/actions/box/add_test.rb +1 -2
  76. data/test/vagrant/actions/box/destroy_test.rb +0 -1
  77. data/test/vagrant/actions/box/download_test.rb +40 -15
  78. data/test/vagrant/actions/box/unpackage_test.rb +2 -3
  79. data/test/vagrant/actions/collection_test.rb +8 -5
  80. data/test/vagrant/actions/runner_test.rb +8 -6
  81. data/test/vagrant/actions/vm/boot_test.rb +12 -11
  82. data/test/vagrant/actions/vm/customize_test.rb +2 -3
  83. data/test/vagrant/actions/vm/destroy_test.rb +2 -3
  84. data/test/vagrant/actions/vm/down_test.rb +16 -3
  85. data/test/vagrant/actions/vm/export_test.rb +4 -5
  86. data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
  87. data/test/vagrant/actions/vm/halt_test.rb +8 -2
  88. data/test/vagrant/actions/vm/import_test.rb +5 -5
  89. data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
  90. data/test/vagrant/actions/vm/package_test.rb +60 -22
  91. data/test/vagrant/actions/vm/provision_test.rb +7 -16
  92. data/test/vagrant/actions/vm/reload_test.rb +3 -2
  93. data/test/vagrant/actions/vm/resume_test.rb +0 -1
  94. data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
  95. data/test/vagrant/actions/vm/start_test.rb +10 -3
  96. data/test/vagrant/actions/vm/suspend_test.rb +1 -2
  97. data/test/vagrant/actions/vm/up_test.rb +19 -11
  98. data/test/vagrant/active_list_test.rb +148 -129
  99. data/test/vagrant/box_test.rb +26 -14
  100. data/test/vagrant/busy_test.rb +15 -6
  101. data/test/vagrant/command_test.rb +53 -0
  102. data/test/vagrant/commands/base_test.rb +118 -0
  103. data/test/vagrant/commands/box/add_test.rb +34 -0
  104. data/test/vagrant/commands/box/list_test.rb +32 -0
  105. data/test/vagrant/commands/box/remove_test.rb +41 -0
  106. data/test/vagrant/commands/destroy_test.rb +32 -0
  107. data/test/vagrant/commands/down_test.rb +17 -0
  108. data/test/vagrant/commands/halt_test.rb +28 -0
  109. data/test/vagrant/commands/init_test.rb +55 -0
  110. data/test/vagrant/commands/package_test.rb +84 -0
  111. data/test/vagrant/commands/reload_test.rb +28 -0
  112. data/test/vagrant/commands/resume_test.rb +33 -0
  113. data/test/vagrant/commands/ssh_config_test.rb +54 -0
  114. data/test/vagrant/commands/ssh_test.rb +32 -0
  115. data/test/vagrant/commands/status_test.rb +20 -0
  116. data/test/vagrant/commands/suspend_test.rb +33 -0
  117. data/test/vagrant/commands/up_test.rb +41 -0
  118. data/test/vagrant/config_test.rb +42 -17
  119. data/test/vagrant/downloaders/file_test.rb +7 -0
  120. data/test/vagrant/downloaders/http_test.rb +12 -0
  121. data/test/vagrant/environment_test.rb +595 -0
  122. data/test/vagrant/provisioners/base_test.rb +7 -1
  123. data/test/vagrant/provisioners/chef_server_test.rb +41 -51
  124. data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
  125. data/test/vagrant/provisioners/chef_test.rb +61 -15
  126. data/test/vagrant/ssh_test.rb +166 -38
  127. data/test/vagrant/util/errors_test.rb +57 -0
  128. data/test/vagrant/util/progress_meter_test.rb +33 -0
  129. data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
  130. data/test/vagrant/util/template_renderer_test.rb +138 -0
  131. data/test/vagrant/vm_test.rb +3 -2
  132. data/vagrant.gemspec +88 -33
  133. metadata +94 -51
  134. data/bin/vagrant-box +0 -34
  135. data/bin/vagrant-down +0 -27
  136. data/bin/vagrant-halt +0 -28
  137. data/bin/vagrant-init +0 -27
  138. data/bin/vagrant-package +0 -29
  139. data/bin/vagrant-reload +0 -29
  140. data/bin/vagrant-resume +0 -27
  141. data/bin/vagrant-ssh +0 -27
  142. data/bin/vagrant-status +0 -29
  143. data/bin/vagrant-suspend +0 -27
  144. data/bin/vagrant-up +0 -29
  145. data/lib/vagrant/commands.rb +0 -234
  146. data/lib/vagrant/env.rb +0 -189
  147. data/lib/vagrant/stacked_proc_runner.rb +0 -33
  148. data/test/vagrant/commands_test.rb +0 -269
  149. data/test/vagrant/env_test.rb +0 -418
@@ -2,36 +2,40 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class BoxTest < Test::Unit::TestCase
4
4
  context "class methods" do
5
+ setup do
6
+ @env = mock_environment
7
+ end
8
+
5
9
  context "listing all boxes" do
6
10
  setup do
7
11
  Dir.stubs(:open)
8
12
  File.stubs(:directory?).returns(true)
9
13
 
10
14
  @boxes_path = "foo"
11
- Vagrant::Env.stubs(:boxes_path).returns(@boxes_path)
15
+ @env.stubs(:boxes_path).returns(@boxes_path)
12
16
  end
13
17
 
14
18
  should "open the boxes directory" do
15
- Dir.expects(:open).with(Vagrant::Env.boxes_path)
16
- Vagrant::Box.all
19
+ Dir.expects(:open).with(@env.boxes_path)
20
+ Vagrant::Box.all(@env)
17
21
  end
18
22
 
19
23
  should "return an array" do
20
- result = Vagrant::Box.all
24
+ result = Vagrant::Box.all(@env)
21
25
  assert result.is_a?(Array)
22
26
  end
23
27
 
24
28
  should "not return the '.' and '..' directories" do
25
29
  dir = [".", "..", "..", ".", ".."]
26
30
  Dir.expects(:open).yields(dir)
27
- result = Vagrant::Box.all
31
+ result = Vagrant::Box.all(@env)
28
32
  assert result.empty?
29
33
  end
30
34
 
31
35
  should "return the other directories" do
32
36
  dir = [".", "foo", "bar", "baz"]
33
37
  Dir.expects(:open).yields(dir)
34
- result = Vagrant::Box.all
38
+ result = Vagrant::Box.all(@env)
35
39
  assert_equal ["foo", "bar", "baz"], result
36
40
  end
37
41
 
@@ -44,7 +48,7 @@ class BoxTest < Test::Unit::TestCase
44
48
  File.expects(:directory?).with(File.join(@boxes_path, dir)).returns(files[index]).in_sequence(dir_sequence)
45
49
  end
46
50
 
47
- result = Vagrant::Box.all
51
+ result = Vagrant::Box.all(@env)
48
52
  assert_equal ["foo"], result
49
53
  end
50
54
  end
@@ -53,20 +57,27 @@ class BoxTest < Test::Unit::TestCase
53
57
  setup do
54
58
  @dir = "foo"
55
59
  @name = "bar"
56
- Vagrant::Box.stubs(:directory).with(@name).returns(@dir)
60
+ Vagrant::Box.stubs(:directory).with(@env, @name).returns(@dir)
57
61
  end
58
62
 
59
63
  should "return nil if the box doesn't exist" do
60
64
  File.expects(:directory?).with(@dir).once.returns(false)
61
- assert_nil Vagrant::Box.find(@name)
65
+ assert_nil Vagrant::Box.find(@env, @name)
62
66
  end
63
67
 
64
68
  should "return a box object with the proper name set" do
65
69
  File.expects(:directory?).with(@dir).once.returns(true)
66
- result = Vagrant::Box.find(@name)
70
+ result = Vagrant::Box.find(@env, @name)
67
71
  assert result
68
72
  assert_equal @name, result.name
69
73
  end
74
+
75
+ should "return a box object with the proper env set" do
76
+ File.expects(:directory?).with(@dir).once.returns(true)
77
+ result = Vagrant::Box.find(@env, @name)
78
+ assert result
79
+ assert_equal @env, result.env
80
+ end
70
81
  end
71
82
 
72
83
  context "adding" do
@@ -79,20 +90,21 @@ class BoxTest < Test::Unit::TestCase
79
90
  box = mock("box")
80
91
  box.expects(:name=).with(@name)
81
92
  box.expects(:uri=).with(@uri)
93
+ box.expects(:env=).with(@env)
82
94
  box.expects(:add).once
83
95
  Vagrant::Box.expects(:new).returns(box)
84
- Vagrant::Box.add(@name, @uri)
96
+ Vagrant::Box.add(@env, @name, @uri)
85
97
  end
86
98
  end
87
99
 
88
100
  context "box directory" do
89
101
  setup do
90
102
  @name = "foo"
91
- @box_dir = File.join(Vagrant::Env.boxes_path, @name)
103
+ @box_dir = File.join(@env.boxes_path, @name)
92
104
  end
93
105
 
94
106
  should "return the boxes_path joined with the name" do
95
- assert_equal @box_dir, Vagrant::Box.directory(@name)
107
+ assert_equal @box_dir, Vagrant::Box.directory(@env, @name)
96
108
  end
97
109
  end
98
110
  end
@@ -114,7 +126,7 @@ class BoxTest < Test::Unit::TestCase
114
126
 
115
127
  should "return the boxes_path joined with the name" do
116
128
  result = mock("object")
117
- Vagrant::Box.expects(:directory).with(@box.name).returns(result)
129
+ Vagrant::Box.expects(:directory).with(@box.env, @box.name).returns(result)
118
130
  assert result.equal?(@box.directory)
119
131
  end
120
132
  end
@@ -1,19 +1,28 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class BusyTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Busy
6
+ end
7
+
4
8
  context "waiting for not busy" do
5
9
  setup do
6
- Vagrant::Busy.reset_trap_thread!
10
+ @klass.reset_trap_thread!
7
11
  end
8
12
 
9
13
  should "run in a thread" do
10
14
  Thread.expects(:new).once.returns(nil)
11
- Vagrant::Busy.wait_for_not_busy
15
+ @klass.wait_for_not_busy
12
16
  end
13
17
 
14
- should "not start a thread multiple times" do
15
- Thread.expects(:new).once.returns("foo")
16
- Vagrant::Busy.wait_for_not_busy
18
+ should "immediately exit on second call" do
19
+ tid = "foo"
20
+ Thread.expects(:new).once.returns(tid)
21
+ @klass.wait_for_not_busy
22
+
23
+ Thread.expects(:kill).once.with(tid)
24
+ @klass.expects(:abort).once
25
+ @klass.wait_for_not_busy
17
26
  end
18
27
  end
19
28
 
@@ -42,7 +51,7 @@ class BusyTest < Test::Unit::TestCase
42
51
  should "complete the trap thread even if an exception occurs" do
43
52
  trap_thread = mock("trap_thread")
44
53
  trap_thread.expects(:join).once
45
- Vagrant::Busy.stubs(:trap_thread).returns(trap_thread)
54
+ @klass.stubs(:trap_thread).returns(trap_thread)
46
55
 
47
56
  assert_raise Exception do
48
57
  Vagrant.busy do
@@ -0,0 +1,53 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class CommandTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Command
6
+ end
7
+
8
+ context "initializing" do
9
+ setup do
10
+ @env = mock("environment")
11
+ end
12
+
13
+ should "set the env attribute" do
14
+ @instance = @klass.new(@env)
15
+ assert_equal @env, @instance.env
16
+ end
17
+ end
18
+
19
+ context "class methods" do
20
+ context "executing" do
21
+ should "load the environment then send the command on commands" do
22
+ env = mock("env")
23
+ commands = mock("commands")
24
+ env.stubs(:commands).returns(commands)
25
+ Vagrant::Environment.expects(:load!).returns(env)
26
+ commands.expects(:subcommand).with(1,2,3).once
27
+
28
+ @klass.execute(1,2,3)
29
+ end
30
+ end
31
+ end
32
+
33
+ context "with an instance" do
34
+ setup do
35
+ @env = mock_environment
36
+ @instance = @klass.new(@env)
37
+ end
38
+
39
+ context "subcommands" do
40
+ setup do
41
+ @raw_name = :bar
42
+ @name = :foo
43
+ @instance.stubs(:camelize).with(@raw_name).returns(@name)
44
+ end
45
+
46
+ should "send the env, name, and args to the base class" do
47
+ args = [1,2,3]
48
+ Vagrant::Commands::Base.expects(:dispatch).with(@env, @name, *args)
49
+ @instance.subcommand(@name, *args)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,118 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsBaseTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Base
6
+ end
7
+
8
+ context "initializing" do
9
+ should "setup the env attribute" do
10
+ env = mock("env")
11
+ instance = @klass.new(env)
12
+ assert_equal env, instance.env
13
+ end
14
+ end
15
+
16
+ context "class methods" do
17
+ setup do
18
+ @env = mock_environment
19
+ @klass.subcommands.clear
20
+ end
21
+
22
+ context "registering commands" do
23
+ should "register commands" do
24
+ klass = mock("klass")
25
+ @klass.subcommand("init", klass)
26
+ assert_equal klass, @klass.subcommands["init"]
27
+ end
28
+ end
29
+
30
+ context "dispatching to subcommands" do
31
+ setup do
32
+ @command_klass = mock("klass")
33
+ @name = "init"
34
+ @klass.subcommand(@name, @command_klass)
35
+
36
+ @args = [1,2,3]
37
+ end
38
+
39
+ should "call dispatch on child if subcommand is found" do
40
+ @command_klass.expects(:dispatch).with(@env, *@args)
41
+ @klass.dispatch(@env, @name, *@args)
42
+ end
43
+
44
+ should "instantiate and execute when no subcommand is found" do
45
+ instance = mock("instance")
46
+ @klass.expects(:new).with(@env).returns(instance)
47
+ instance.expects(:execute).with(@args)
48
+ @klass.dispatch(@env, *@args)
49
+ end
50
+ end
51
+
52
+ context "descriptions" do
53
+ should "be able to set description" do
54
+ description = "The lazy fox yada yada"
55
+ @klass.description(description)
56
+ assert_equal description, @klass.description
57
+ end
58
+ end
59
+ end
60
+
61
+ context "instance methods" do
62
+ setup do
63
+ @env = mock_environment
64
+ @instance = @klass.new(@env)
65
+ end
66
+
67
+ context "executing" do
68
+ should "show version if flag is set" do
69
+ @instance.expects(:puts_version).once
70
+ @instance.expects(:puts_help).never
71
+ @instance.execute(["--version"])
72
+ end
73
+
74
+ should "just print the help by default" do
75
+ @instance.expects(:puts_version).never
76
+ @klass.expects(:puts_help)
77
+ @instance.execute([])
78
+ end
79
+ end
80
+
81
+ context "getting the option parser" do
82
+ should "create it with the options spec if it hasn't been created yet" do
83
+ opts = mock("opts")
84
+ result = mock("result")
85
+ OptionParser.expects(:new).yields(opts).returns(result)
86
+ @instance.expects(:options_spec).with(opts)
87
+
88
+ assert_equal result, @instance.option_parser(true)
89
+ end
90
+
91
+ should "not create it once its been created" do
92
+ result = mock("result")
93
+ OptionParser.expects(:new).once.returns(result)
94
+
95
+ assert_equal result, @instance.option_parser(true)
96
+ assert_equal result, @instance.option_parser
97
+ assert_equal result, @instance.option_parser
98
+ end
99
+ end
100
+
101
+ context "parsing options" do
102
+ setup do
103
+ @args = []
104
+
105
+ @options = mock("options")
106
+ @option_parser = mock("option_parser")
107
+
108
+ @instance.stubs(:option_parser).returns(@option_parser)
109
+ @instance.stubs(:options).returns(@options)
110
+ end
111
+
112
+ should "parse the options with the args" do
113
+ @option_parser.expects(:parse!).with(@args).once
114
+ assert_equal @options, @instance.parse_options(@args)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
+
3
+ class CommandsBoxAddTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Box::Add
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ setup do
19
+ @name = "foo"
20
+ @path = "bar"
21
+ end
22
+
23
+ should "execute the add action with the name and path" do
24
+ Vagrant::Box.expects(:add).with(@env, @name, @path).once
25
+ @instance.execute([@name, @path])
26
+ end
27
+
28
+ should "show help if not enough arguments" do
29
+ Vagrant::Box.expects(:add).never
30
+ @instance.expects(:show_help).once
31
+ @instance.execute([])
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
+
3
+ class CommandsBoxListTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Box::List
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ setup do
19
+ @boxes = ["foo", "bar"]
20
+
21
+ Vagrant::Box.stubs(:all).returns(@boxes)
22
+ @instance.stubs(:wrap_output)
23
+ end
24
+
25
+ should "call all on box and sort the results" do
26
+ @all = mock("all")
27
+ @all.expects(:sort).returns(@boxes)
28
+ Vagrant::Box.expects(:all).with(@env).returns(@all)
29
+ @instance.execute
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
+
3
+ class CommandsBoxRemoveTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Box::Remove
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ setup do
19
+ @name = "foo"
20
+ end
21
+
22
+ should "show help if not enough arguments" do
23
+ Vagrant::Box.expects(:find).never
24
+ @instance.expects(:show_help).once
25
+ @instance.execute([])
26
+ end
27
+
28
+ should "error and exit if the box doesn't exist" do
29
+ Vagrant::Box.expects(:find).returns(nil)
30
+ @instance.expects(:error_and_exit).with(:box_remove_doesnt_exist).once
31
+ @instance.execute([@name])
32
+ end
33
+
34
+ should "call destroy on the box if it exists" do
35
+ @box = mock("box")
36
+ Vagrant::Box.expects(:find).with(@env, @name).returns(@box)
37
+ @box.expects(:destroy).once
38
+ @instance.execute([@name])
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsDestroyTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Destroy
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ setup do
19
+ @persisted_vm.stubs(:destroy)
20
+ end
21
+
22
+ should "require a persisted VM" do
23
+ @env.expects(:require_persisted_vm).once
24
+ @instance.execute
25
+ end
26
+
27
+ should "destroy the persisted VM and the VM image" do
28
+ @persisted_vm.expects(:destroy).once
29
+ @instance.execute
30
+ end
31
+ end
32
+ end