vagrant 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/README.md +1 -0
  2. data/config/default.rb +6 -6
  3. data/lib/vagrant.rb +6 -3
  4. data/lib/vagrant/action.rb +77 -0
  5. data/lib/vagrant/action/action_exception.rb +16 -0
  6. data/lib/vagrant/action/box/destroy.rb +19 -0
  7. data/lib/vagrant/action/box/download.rb +78 -0
  8. data/lib/vagrant/action/box/unpackage.rb +58 -0
  9. data/lib/vagrant/action/box/verify.rb +23 -0
  10. data/lib/vagrant/action/builder.rb +151 -0
  11. data/lib/vagrant/action/builtin.rb +114 -0
  12. data/lib/vagrant/action/env/error_halt.rb +16 -0
  13. data/lib/vagrant/action/env/set.rb +18 -0
  14. data/lib/vagrant/action/environment.rb +98 -0
  15. data/lib/vagrant/action/exception_catcher.rb +14 -0
  16. data/lib/vagrant/action/vm/boot.rb +54 -0
  17. data/lib/vagrant/action/vm/check_box.rb +27 -0
  18. data/lib/vagrant/action/vm/check_guest_additions.rb +32 -0
  19. data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
  20. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
  21. data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
  22. data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
  23. data/lib/vagrant/action/vm/customize.rb +21 -0
  24. data/lib/vagrant/action/vm/destroy.rb +20 -0
  25. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +35 -0
  26. data/lib/vagrant/action/vm/disable_networks.rb +26 -0
  27. data/lib/vagrant/action/vm/export.rb +53 -0
  28. data/lib/vagrant/action/vm/forward_ports.rb +121 -0
  29. data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
  30. data/lib/vagrant/action/vm/halt.rb +34 -0
  31. data/lib/vagrant/action/vm/import.rb +33 -0
  32. data/lib/vagrant/action/vm/match_mac_address.rb +19 -0
  33. data/lib/vagrant/{actions → action}/vm/network.rb +47 -55
  34. data/lib/vagrant/action/vm/nfs.rb +161 -0
  35. data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
  36. data/lib/vagrant/action/vm/package.rb +99 -0
  37. data/lib/vagrant/action/vm/persist.rb +22 -0
  38. data/lib/vagrant/action/vm/provision.rb +50 -0
  39. data/lib/vagrant/action/vm/resume.rb +20 -0
  40. data/lib/vagrant/{actions/vm/shared_folders.rb → action/vm/share_folders.rb} +48 -45
  41. data/lib/vagrant/action/vm/suspend.rb +20 -0
  42. data/lib/vagrant/box.rb +3 -7
  43. data/lib/vagrant/commands/base.rb +1 -3
  44. data/lib/vagrant/commands/package.rb +4 -9
  45. data/lib/vagrant/commands/up.rb +0 -2
  46. data/lib/vagrant/config.rb +15 -1
  47. data/lib/vagrant/downloaders/file.rb +1 -1
  48. data/lib/vagrant/downloaders/http.rb +2 -1
  49. data/lib/vagrant/environment.rb +18 -14
  50. data/lib/vagrant/hosts/base.rb +77 -0
  51. data/lib/vagrant/hosts/bsd.rb +53 -0
  52. data/lib/vagrant/hosts/linux.rb +52 -0
  53. data/lib/vagrant/provisioners/base.rb +17 -9
  54. data/lib/vagrant/provisioners/chef.rb +1 -1
  55. data/lib/vagrant/provisioners/chef_server.rb +4 -8
  56. data/lib/vagrant/provisioners/chef_solo.rb +1 -2
  57. data/lib/vagrant/ssh.rb +12 -4
  58. data/lib/vagrant/systems/base.rb +4 -0
  59. data/lib/vagrant/systems/linux.rb +12 -1
  60. data/lib/vagrant/util.rb +16 -0
  61. data/lib/vagrant/util/busy.rb +59 -0
  62. data/lib/vagrant/util/plain_logger.rb +11 -0
  63. data/lib/vagrant/util/platform.rb +18 -0
  64. data/lib/vagrant/util/resource_logger.rb +128 -0
  65. data/lib/vagrant/version.rb +6 -0
  66. data/lib/vagrant/vm.rb +10 -12
  67. data/templates/chef_solo_solo.erb +2 -1
  68. data/templates/nfs/exports.erb +3 -0
  69. data/templates/nfs/exports_linux.erb +3 -0
  70. data/templates/strings.yml +23 -3
  71. metadata +128 -198
  72. data/.gitignore +0 -11
  73. data/Gemfile +0 -18
  74. data/Rakefile +0 -41
  75. data/VERSION +0 -1
  76. data/bin/.gitignore +0 -0
  77. data/lib/vagrant/actions/base.rb +0 -130
  78. data/lib/vagrant/actions/box/add.rb +0 -23
  79. data/lib/vagrant/actions/box/destroy.rb +0 -14
  80. data/lib/vagrant/actions/box/download.rb +0 -67
  81. data/lib/vagrant/actions/box/unpackage.rb +0 -42
  82. data/lib/vagrant/actions/box/verify.rb +0 -32
  83. data/lib/vagrant/actions/collection.rb +0 -36
  84. data/lib/vagrant/actions/runner.rb +0 -131
  85. data/lib/vagrant/actions/vm/boot.rb +0 -43
  86. data/lib/vagrant/actions/vm/customize.rb +0 -19
  87. data/lib/vagrant/actions/vm/destroy.rb +0 -24
  88. data/lib/vagrant/actions/vm/down.rb +0 -22
  89. data/lib/vagrant/actions/vm/export.rb +0 -45
  90. data/lib/vagrant/actions/vm/forward_ports.rb +0 -134
  91. data/lib/vagrant/actions/vm/halt.rb +0 -24
  92. data/lib/vagrant/actions/vm/import.rb +0 -23
  93. data/lib/vagrant/actions/vm/move_hard_drive.rb +0 -51
  94. data/lib/vagrant/actions/vm/package.rb +0 -94
  95. data/lib/vagrant/actions/vm/provision.rb +0 -49
  96. data/lib/vagrant/actions/vm/reload.rb +0 -17
  97. data/lib/vagrant/actions/vm/resume.rb +0 -16
  98. data/lib/vagrant/actions/vm/start.rb +0 -26
  99. data/lib/vagrant/actions/vm/suspend.rb +0 -16
  100. data/lib/vagrant/actions/vm/up.rb +0 -53
  101. data/lib/vagrant/busy.rb +0 -79
  102. data/lib/vagrant/resource_logger.rb +0 -126
  103. data/lib/vagrant/util/error_helper.rb +0 -13
  104. data/lib/vagrant/util/output_helper.rb +0 -9
  105. data/test/test_helper.rb +0 -149
  106. data/test/vagrant/actions/base_test.rb +0 -32
  107. data/test/vagrant/actions/box/add_test.rb +0 -36
  108. data/test/vagrant/actions/box/destroy_test.rb +0 -17
  109. data/test/vagrant/actions/box/download_test.rb +0 -137
  110. data/test/vagrant/actions/box/unpackage_test.rb +0 -99
  111. data/test/vagrant/actions/box/verify_test.rb +0 -44
  112. data/test/vagrant/actions/collection_test.rb +0 -113
  113. data/test/vagrant/actions/runner_test.rb +0 -268
  114. data/test/vagrant/actions/vm/boot_test.rb +0 -49
  115. data/test/vagrant/actions/vm/customize_test.rb +0 -21
  116. data/test/vagrant/actions/vm/destroy_test.rb +0 -37
  117. data/test/vagrant/actions/vm/down_test.rb +0 -39
  118. data/test/vagrant/actions/vm/export_test.rb +0 -88
  119. data/test/vagrant/actions/vm/forward_ports_test.rb +0 -253
  120. data/test/vagrant/actions/vm/halt_test.rb +0 -65
  121. data/test/vagrant/actions/vm/import_test.rb +0 -45
  122. data/test/vagrant/actions/vm/move_hard_drive_test.rb +0 -106
  123. data/test/vagrant/actions/vm/network_test.rb +0 -291
  124. data/test/vagrant/actions/vm/package_test.rb +0 -254
  125. data/test/vagrant/actions/vm/provision_test.rb +0 -99
  126. data/test/vagrant/actions/vm/reload_test.rb +0 -46
  127. data/test/vagrant/actions/vm/resume_test.rb +0 -26
  128. data/test/vagrant/actions/vm/shared_folders_test.rb +0 -211
  129. data/test/vagrant/actions/vm/start_test.rb +0 -73
  130. data/test/vagrant/actions/vm/suspend_test.rb +0 -26
  131. data/test/vagrant/actions/vm/up_test.rb +0 -96
  132. data/test/vagrant/active_list_test.rb +0 -173
  133. data/test/vagrant/box_test.rb +0 -154
  134. data/test/vagrant/busy_test.rb +0 -78
  135. data/test/vagrant/command_test.rb +0 -53
  136. data/test/vagrant/commands/base_test.rb +0 -139
  137. data/test/vagrant/commands/box/add_test.rb +0 -34
  138. data/test/vagrant/commands/box/list_test.rb +0 -32
  139. data/test/vagrant/commands/box/remove_test.rb +0 -41
  140. data/test/vagrant/commands/destroy_test.rb +0 -44
  141. data/test/vagrant/commands/halt_test.rb +0 -50
  142. data/test/vagrant/commands/init_test.rb +0 -55
  143. data/test/vagrant/commands/package_test.rb +0 -104
  144. data/test/vagrant/commands/provision_test.rb +0 -60
  145. data/test/vagrant/commands/reload_test.rb +0 -44
  146. data/test/vagrant/commands/resume_test.rb +0 -44
  147. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  148. data/test/vagrant/commands/ssh_test.rb +0 -129
  149. data/test/vagrant/commands/status_test.rb +0 -40
  150. data/test/vagrant/commands/suspend_test.rb +0 -44
  151. data/test/vagrant/commands/up_test.rb +0 -47
  152. data/test/vagrant/config_test.rb +0 -287
  153. data/test/vagrant/downloaders/base_test.rb +0 -28
  154. data/test/vagrant/downloaders/file_test.rb +0 -33
  155. data/test/vagrant/downloaders/http_test.rb +0 -62
  156. data/test/vagrant/environment_test.rb +0 -770
  157. data/test/vagrant/provisioners/base_test.rb +0 -33
  158. data/test/vagrant/provisioners/chef_server_test.rb +0 -176
  159. data/test/vagrant/provisioners/chef_solo_test.rb +0 -183
  160. data/test/vagrant/provisioners/chef_test.rb +0 -175
  161. data/test/vagrant/resource_logger_test.rb +0 -145
  162. data/test/vagrant/ssh_session_test.rb +0 -46
  163. data/test/vagrant/ssh_test.rb +0 -296
  164. data/test/vagrant/systems/linux_test.rb +0 -179
  165. data/test/vagrant/util/error_helper_test.rb +0 -5
  166. data/test/vagrant/util/output_helper_test.rb +0 -5
  167. data/test/vagrant/util/plain_logger_test.rb +0 -17
  168. data/test/vagrant/util/platform_test.rb +0 -18
  169. data/test/vagrant/util/stacked_proc_runner_test.rb +0 -43
  170. data/test/vagrant/util/template_renderer_test.rb +0 -144
  171. data/test/vagrant/util/translator_test.rb +0 -61
  172. data/test/vagrant/util_test.rb +0 -27
  173. data/test/vagrant/vm_test.rb +0 -235
  174. data/vagrant.gemspec +0 -291
@@ -1,179 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class LinuxSystemTest < Test::Unit::TestCase
4
- setup do
5
- @klass = Vagrant::Systems::Linux
6
- @ssh = mock("ssh")
7
- @mock_env = mock_environment
8
- @vm = mock("vm")
9
- @vm.stubs(:env).returns(@mock_env)
10
- @instance = @klass.new(@vm)
11
- end
12
-
13
- context "halting" do
14
- setup do
15
- @ssh_session = mock("ssh_session")
16
- @ssh.stubs(:execute).yields(@ssh_session)
17
- @vm.stubs(:ssh).returns(@ssh)
18
-
19
- @real_vm = mock("real_vm")
20
- @real_vm.stubs(:state).returns(:powered_off)
21
- @vm.stubs(:vm).returns(@real_vm)
22
- end
23
-
24
- should "execute halt via SSH" do
25
- @ssh_session.expects(:exec!).with("sudo halt").once
26
- @instance.halt
27
- end
28
- end
29
-
30
- context "mounting shared folders" do
31
- setup do
32
- @name = "foo"
33
- @guestpath = "/bar"
34
- end
35
-
36
- should "create the dir, mount the folder, then set permissions" do
37
- mount_seq = sequence("mount_seq")
38
- @ssh.expects(:exec!).with("sudo mkdir -p #{@guestpath}").in_sequence(mount_seq)
39
- @instance.expects(:mount_folder).with(@ssh, @name, @guestpath).in_sequence(mount_seq)
40
- @ssh.expects(:exec!).with("sudo chown #{@vm.env.config.ssh.username} #{@guestpath}").in_sequence(mount_seq)
41
-
42
- @instance.mount_shared_folder(@ssh, @name, @guestpath)
43
- end
44
- end
45
-
46
- context "preparing unison" do
47
- setup do
48
- @ssh.stubs(:exec!)
49
- @ssh.stubs(:upload!)
50
- @vm.stubs(:ssh).returns(@ssh)
51
- end
52
-
53
- should "upload the script" do
54
- @vm.ssh.expects(:upload!).with do |script, path|
55
- assert_equal @mock_env.config.unison.script, path
56
- true
57
- end
58
-
59
- @instance.prepare_unison(@ssh)
60
- end
61
-
62
- should "make the script executable" do
63
- @ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.unison.script}").once
64
- @instance.prepare_unison(@ssh)
65
- end
66
-
67
- should "remove old crontab entry file" do
68
- @ssh.expects(:exec!).with("sudo rm #{@mock_env.config.unison.crontab_entry_file}", :error_check => false).once
69
- @instance.prepare_unison(@ssh)
70
- end
71
- end
72
-
73
- context "creating unison entry" do
74
- setup do
75
- @ssh.stubs(:exec!)
76
- @options = {
77
- :guestpath => "foo",
78
- :original => { :guestpath => "bar!" }
79
- }
80
- end
81
-
82
- should "render the crontab entry with proper variables" do
83
- variables = {
84
- :from => @options[:guestpath],
85
- :to => @options[:original][:guestpath],
86
- :options => @mock_env.config.unison.options,
87
- :script => @mock_env.config.unison.script,
88
- :log_file => @mock_env.config.unison.log_file % "bar-"
89
- }
90
- Vagrant::Util::TemplateRenderer.expects(:render).with('/unison/crontab_entry',
91
- variables).once
92
- @instance.create_unison(@ssh, @options)
93
- end
94
-
95
- should "remove the .unison directory" do
96
- @ssh.expects(:exec!).with("sudo rm -rf ~/.unison")
97
- @instance.create_unison(@ssh, @options)
98
- end
99
-
100
- should "remove the original guestpath" do
101
- @ssh.expects(:exec!).with("sudo rm -rf #{@options[:original][:guestpath]}")
102
- @instance.create_unison(@ssh, @options)
103
- end
104
-
105
- should "enable the crontab file" do
106
- @ssh.expects(:exec!).with("crontab #{@mock_env.config.unison.crontab_entry_file}")
107
- @instance.create_unison(@ssh, @options)
108
- end
109
- end
110
-
111
- #-------------------------------------------------------------------
112
- # "Private" methods tests
113
- #-------------------------------------------------------------------
114
- context "mounting the main folder" do
115
- setup do
116
- @name = "foo"
117
- @guestpath = "bar"
118
- @sleeptime = 0
119
- @limit = 10
120
-
121
- @success_return = false
122
- end
123
-
124
- def mount_folder
125
- @instance.mount_folder(@ssh, @name, @guestpath, @sleeptime)
126
- end
127
-
128
- should "execute the proper mount command" do
129
- @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{@vm.env.config.ssh.username},gid=#{@vm.env.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return)
130
- mount_folder
131
- end
132
-
133
- should "test type of text and text string to detect error" do
134
- data = mock("data")
135
- data.expects(:[]=).with(:result, !@success_return)
136
-
137
- @ssh.expects(:exec!).yields(data, :stderr, "No such device").returns(@success_return)
138
- mount_folder
139
- end
140
-
141
- should "test type of text and test string to detect success" do
142
- data = mock("data")
143
- data.expects(:[]=).with(:result, @success_return)
144
-
145
- @ssh.expects(:exec!).yields(data, :stdout, "Nothing such device").returns(@success_return)
146
- mount_folder
147
- end
148
-
149
- should "raise an ActionException if the command fails constantly" do
150
- @ssh.expects(:exec!).times(@limit).returns(!@success_return)
151
-
152
- assert_raises(Vagrant::Actions::ActionException) {
153
- mount_folder
154
- }
155
- end
156
-
157
- should "not raise any exception if the command succeeded" do
158
- @ssh.expects(:exec!).once.returns(@success_return)
159
-
160
- assert_nothing_raised {
161
- mount_folder
162
- }
163
- end
164
-
165
- should "add uid AND gid to mount" do
166
- uid = "foo"
167
- gid = "bar"
168
- env = mock_environment do |config|
169
- config.vm.shared_folder_uid = uid
170
- config.vm.shared_folder_gid = gid
171
- end
172
-
173
- @vm.stubs(:env).returns(env)
174
-
175
- @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return)
176
- mount_folder
177
- end
178
- end
179
- end
@@ -1,5 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class ErrorHelperUtilTest < Test::Unit::TestCase
4
- # TODO
5
- end
@@ -1,5 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class OutputHelperUtilTest < Test::Unit::TestCase
4
- # TODO
5
- end
@@ -1,17 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class PlainLoggerUtilTest < Test::Unit::TestCase
4
- setup do
5
- @klass = Vagrant::Util::PlainLogger
6
- @instance = @klass.new(nil)
7
- end
8
-
9
- should "inherit from the standard logger" do
10
- assert @instance.is_a?(::Logger)
11
- end
12
-
13
- should "just add a newline to the message" do
14
- msg = "foo bar baz"
15
- assert_equal "#{msg}\n", @instance.format_message("1", "2", "3", msg)
16
- end
17
- end
@@ -1,18 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class PlatformTest < Test::Unit::TestCase
4
- context "file options" do
5
- should "include add binary bit to options on windows platform" do
6
- # This constant is not defined on non-windows platforms, so define it here
7
- File::BINARY = 4096 unless defined?(File::BINARY)
8
-
9
- Mario::Platform.expects(:windows?).returns(true)
10
- assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY|File::BINARY
11
- end
12
-
13
- should "not include binary bit on other platforms" do
14
- Mario::Platform.expects(:windows?).returns(false)
15
- assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY
16
- end
17
- end
18
- end
@@ -1,43 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class StackedProcRunnerUtilTest < Test::Unit::TestCase
4
- class TestClass
5
- include Vagrant::Util::StackedProcRunner
6
- end
7
-
8
- setup do
9
- @instance = TestClass.new
10
- @instance.proc_stack.clear
11
- end
12
-
13
- should "not run the procs right away" do
14
- obj = mock("obj")
15
- obj.expects(:foo).never
16
- @instance.push_proc { |config| obj.foo }
17
- @instance.push_proc { |config| obj.foo }
18
- @instance.push_proc { |config| obj.foo }
19
- end
20
-
21
- should "run the blocks when run_procs! is ran" do
22
- obj = mock("obj")
23
- obj.expects(:foo).times(2)
24
- @instance.push_proc { obj.foo }
25
- @instance.push_proc { obj.foo }
26
- @instance.run_procs!
27
- end
28
-
29
- should "run the blocks with the same arguments" do
30
- passed_config = mock("config")
31
- @instance.push_proc { |config| assert passed_config.equal?(config) }
32
- @instance.push_proc { |config| assert passed_config.equal?(config) }
33
- @instance.run_procs!(passed_config)
34
- end
35
-
36
- should "not clear the blocks after running" do
37
- obj = mock("obj")
38
- obj.expects(:foo).times(2)
39
- @instance.push_proc { obj.foo }
40
- @instance.run_procs!
41
- @instance.run_procs!
42
- end
43
- end
@@ -1,144 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class TemplateRendererUtilTest < Test::Unit::TestCase
4
- context "initializing" do
5
- should "set the template to the given argument" do
6
- r = Vagrant::Util::TemplateRenderer.new("foo")
7
- assert_equal "foo", r.template
8
- end
9
-
10
- should "set any additional variables" do
11
- r = Vagrant::Util::TemplateRenderer.new("foo", {:bar => :baz})
12
- assert_equal :baz, r.bar
13
- end
14
- end
15
-
16
- context "rendering" do
17
- setup do
18
- @template = "foo"
19
- @r = Vagrant::Util::TemplateRenderer.new(@template)
20
- @r.stubs(:full_template_path).returns(@template + "!")
21
-
22
- @contents = "bar"
23
-
24
- @file = mock("file")
25
- @file.stubs(:read).returns(@contents)
26
- File.stubs(:open).yields(@file)
27
- end
28
-
29
- should "open the template file for reading" do
30
- File.expects(:open).with(@r.full_template_path, 'r').once
31
- @r.render
32
- end
33
-
34
- should "set the template to the file contents, render, then set it back" do
35
- result = "bar"
36
-
37
- template_seq = sequence("template_seq")
38
- @r.expects(:template=).with(@file.read).in_sequence(template_seq)
39
- @r.expects(:render_string).returns(result).in_sequence(template_seq)
40
- @r.expects(:template=).with(@template).in_sequence(template_seq)
41
- assert_equal result, @r.render
42
- end
43
-
44
- should "render the ERB file in the context of the renderer" do
45
- result = "bar"
46
- template = "<%= foo %>"
47
- @r.foo = result
48
- @file.expects(:read).returns(template)
49
- assert_equal result, @r.render
50
- end
51
- end
52
-
53
- context "rendering as string" do
54
- setup do
55
- @result = "foo"
56
- @erb = mock("erb")
57
- @erb.stubs(:result).returns(@result)
58
-
59
- @r = Vagrant::Util::TemplateRenderer.new("foo")
60
- end
61
-
62
- should "simply render the template as a string" do
63
- ERB.expects(:new).with(@r.template).returns(@erb)
64
- assert_equal @result, @r.render_string
65
- end
66
- end
67
-
68
- context "the full template path" do
69
- setup do
70
- @template = "foo"
71
- @r = Vagrant::Util::TemplateRenderer.new(@template)
72
- end
73
-
74
- should "be the ERB file in the templates directory" do
75
- result = File.join(PROJECT_ROOT, "templates", "#{@template}.erb")
76
- assert_equal result, @r.full_template_path
77
- end
78
-
79
- should "remove duplicate path separators" do
80
- @r.template = "foo///bar"
81
- result = File.join(PROJECT_ROOT, "templates", "foo", "bar.erb")
82
- assert_equal result, @r.full_template_path
83
- end
84
- end
85
-
86
- context "class methods" do
87
- context "render_with method" do
88
- setup do
89
- @template = "foo"
90
- @r = Vagrant::Util::TemplateRenderer.new(@template)
91
- @r.stubs(:render)
92
-
93
- @method = :rawr
94
-
95
- Vagrant::Util::TemplateRenderer.stubs(:new).with(@template, {}).returns(@r)
96
- end
97
-
98
- should "use the second argument as the template" do
99
- Vagrant::Util::TemplateRenderer.expects(:new).with(@template, {}).returns(@r)
100
- Vagrant::Util::TemplateRenderer.render_with(@method, @template)
101
- end
102
-
103
- should "send in additional argument to the renderer" do
104
- data = {:hey => :foo}
105
- Vagrant::Util::TemplateRenderer.expects(:new).with(@template, data).returns(@r)
106
- Vagrant::Util::TemplateRenderer.render_with(@method, @template, data)
107
- end
108
-
109
- should "yield a block if given with the renderer as the argument" do
110
- @r.expects(:yielded=).with(true).once
111
- Vagrant::Util::TemplateRenderer.render_with(@method, @template) do |r|
112
- r.yielded = true
113
- end
114
- end
115
-
116
- should "render the result using the given method" do
117
- result = mock('result')
118
- @r.expects(@method).returns(result)
119
- assert_equal result, Vagrant::Util::TemplateRenderer.render_with(@method, @template)
120
- end
121
-
122
- should "convert the given method to a sym prior to calling" do
123
- @r.expects(@method.to_sym).returns(nil)
124
- Vagrant::Util::TemplateRenderer.render_with(@method.to_s, @template)
125
- end
126
- end
127
-
128
- context "render method" do
129
- should "call render_with the render! method" do
130
- args = ["foo", "bar", "baz"]
131
- Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render, *args)
132
- Vagrant::Util::TemplateRenderer.render(*args)
133
- end
134
- end
135
-
136
- context "render_string method" do
137
- should "call render_with the render! method" do
138
- args = ["foo", "bar", "baz"]
139
- Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render_string, *args)
140
- Vagrant::Util::TemplateRenderer.render_string(*args)
141
- end
142
- end
143
- end
144
- end
@@ -1,61 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class TranslatorUtilTest < Test::Unit::TestCase
4
- include Vagrant::Util
5
-
6
- setup do
7
- @klass = Translator
8
- end
9
-
10
- context "loading the errors from the YML" do
11
- setup do
12
- YAML.stubs(:load_file)
13
- @klass.reset!
14
- end
15
-
16
- should "load the file initially, then never again unless reset" do
17
- YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "strings.yml")).once
18
- @klass.strings
19
- @klass.strings
20
- @klass.strings
21
- @klass.strings
22
- end
23
-
24
- should "reload if reset! is called" do
25
- YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "strings.yml")).twice
26
- @klass.strings
27
- @klass.reset!
28
- @klass.strings
29
- end
30
- end
31
-
32
- context "getting the string translated" do
33
- setup do
34
- @strings = {}
35
- @strings[:foo] = "foo bar baz"
36
- @klass.stubs(:strings).returns(@strings)
37
- end
38
-
39
- should "render the error string" do
40
- TemplateRenderer.expects(:render_string).with(@strings[:foo], anything).once
41
- @klass.t(:foo)
42
- end
43
-
44
- should "pass in any data entries" do
45
- data = mock("data")
46
- TemplateRenderer.expects(:render_string).with(@strings[:foo], data).once
47
- @klass.t(:foo, data)
48
- end
49
-
50
- should "return the result of the render" do
51
- result = mock("result")
52
- TemplateRenderer.expects(:render_string).returns(result)
53
- assert_equal result, @klass.t(:foo)
54
- end
55
-
56
- should "return an unknown if the key doesn't exist" do
57
- result = @klass.t(:unknown)
58
- assert result =~ /Unknown/i
59
- end
60
- end
61
- end