@@ -231,40 +231,54 @@ class InstallInstructionTest < InstanceAgentTestCase
231231 context "Parsing a delete file" do
232232 context "an empty delete file" do
233233 setup do
234- @parse_string = <<-END
235- END
236- end
234+ @parse_string = ""
235+ end
237236
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
241241 end
242- end
243242
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 "
249246 File . stubs ( :exist? ) . with ( "test_delete_path" ) . returns ( true )
250247 end
251248
252- should "produce a command that deletes test_delete_path " do
249+ should "use rm for a regular file " do
253250 commands = InstallInstruction . parse_remove_commands ( @parse_string )
254251 FileUtils . expects ( :rm ) . with ( "test_delete_path" )
255- assert_not_equal nil , commands
256252 commands . each do |command |
257253 command . execute
258254 end
259255 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
260277 end
261278
262279 context "multiple files to delete" do
263280 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 "
268282 File . stubs ( :directory? ) . returns ( false )
269283 File . stubs ( :exist? ) . with ( "test_delete_path" ) . returns ( true )
270284 File . stubs ( :exist? ) . with ( "another_delete_path" ) . returns ( true )
@@ -295,11 +309,7 @@ class InstallInstructionTest < InstanceAgentTestCase
295309
296310 context "removes mangled line at the end" do
297311 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"
303313 File . stubs ( :exist? ) . with ( "test_delete_path" ) . returns ( true )
304314 File . stubs ( :exist? ) . with ( "another_delete_path" ) . returns ( true )
305315 end
@@ -318,7 +328,7 @@ class InstallInstructionTest < InstanceAgentTestCase
318328
319329 context "correctly determines method from file type" do
320330 setup do
321- @parse_string = ' foo'
331+ @parse_string = " foo\n "
322332 @instruction_file = mock
323333 @instruction_file . stubs ( :path ) . returns ( "test/123-cleanup" )
324334 File . stubs ( :open ) . with ( "test/123-cleanup" , 'r' ) . returns ( @instruction_file )
0 commit comments