@@ -231,40 +231,54 @@ class InstallInstructionTest < InstanceAgentTestCase
231
231
context "Parsing a delete file" do
232
232
context "an empty delete file" do
233
233
setup do
234
- @parse_string = <<-END
235
- END
236
- end
234
+ @parse_string = ""
235
+ end
237
236
238
- should "return an empty command collection" do
239
- commands = InstallInstruction . parse_remove_commands ( @parse_string )
240
- assert_equal 0 , commands . length
237
+ should "return an empty command collection" do
238
+ commands = InstallInstruction . parse_remove_commands ( @parse_string )
239
+ assert_equal 0 , commands . length
240
+ end
241
241
end
242
- end
243
242
244
- context "a single file to delete" do
245
- setup do
246
- @parse_string = <<-END
247
- test_delete_path
248
- END
243
+ context "a single file to delete" do
244
+ setup do
245
+ @parse_string = "test_delete_path\n "
249
246
File . stubs ( :exist? ) . with ( "test_delete_path" ) . returns ( true )
250
247
end
251
248
252
- should "produce a command that deletes test_delete_path " do
249
+ should "use rm for a regular file " do
253
250
commands = InstallInstruction . parse_remove_commands ( @parse_string )
254
251
FileUtils . expects ( :rm ) . with ( "test_delete_path" )
255
- assert_not_equal nil , commands
256
252
commands . each do |command |
257
253
command . execute
258
254
end
259
255
end
256
+
257
+ should "use rmdir for a directory" do
258
+ File . stubs ( :directory? ) . with ( "test_delete_path" ) . returns ( true )
259
+ commands = InstallInstruction . parse_remove_commands ( @parse_string )
260
+ FileUtils . expects ( :rmdir ) . with ( "test_delete_path" )
261
+ commands . each do |command |
262
+ command . execute
263
+ end
264
+ end
265
+
266
+ should "ignore a non-empty directory by rescuing Errno::ENOTEMPTY" do
267
+ File . stubs ( :directory? ) . with ( "test_delete_path" ) . returns ( true )
268
+ commands = InstallInstruction . parse_remove_commands ( @parse_string )
269
+ FileUtils . stubs ( :rmdir ) . raises ( Errno ::ENOTEMPTY )
270
+
271
+ assert_nothing_raised do
272
+ commands . each do |command |
273
+ command . execute
274
+ end
275
+ end
276
+ end
260
277
end
261
278
262
279
context "multiple files to delete" do
263
280
setup do
264
- @parse_string = <<-END
265
- test_delete_path
266
- another_delete_path
267
- END
281
+ @parse_string = "test_delete_path\n another_delete_path\n "
268
282
File . stubs ( :directory? ) . returns ( false )
269
283
File . stubs ( :exist? ) . with ( "test_delete_path" ) . returns ( true )
270
284
File . stubs ( :exist? ) . with ( "another_delete_path" ) . returns ( true )
@@ -295,11 +309,7 @@ class InstallInstructionTest < InstanceAgentTestCase
295
309
296
310
context "removes mangled line at the end" do
297
311
setup do
298
- @parse_string = <<-END
299
- test_delete_path
300
- another_delete_path
301
- END
302
- @parse_string << "mangled"
312
+ @parse_string = "test_delete_path\n another_delete_path\n mangled"
303
313
File . stubs ( :exist? ) . with ( "test_delete_path" ) . returns ( true )
304
314
File . stubs ( :exist? ) . with ( "another_delete_path" ) . returns ( true )
305
315
end
@@ -318,7 +328,7 @@ class InstallInstructionTest < InstanceAgentTestCase
318
328
319
329
context "correctly determines method from file type" do
320
330
setup do
321
- @parse_string = ' foo'
331
+ @parse_string = " foo\n "
322
332
@instruction_file = mock
323
333
@instruction_file . stubs ( :path ) . returns ( "test/123-cleanup" )
324
334
File . stubs ( :open ) . with ( "test/123-cleanup" , 'r' ) . returns ( @instruction_file )
0 commit comments