summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-18 15:34:35 +0200
committerPaul Buetow <paul@buetow.org>2025-02-18 15:34:35 +0200
commit06ce663886c56b96ef25b31f0463e2207f7321fd (patch)
treef1d07445c1680d0e6737c15bdd0020c7b9126bd1
parentfdbd63c6798c6c92b482d03b1f197cbeb41a5448 (diff)
add support to delete a file
-rw-r--r--lib/dslkeywords/file.rb5
-rw-r--r--test/lib/dslkeywords/file_test.rb17
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb
index 020a97f..41b8cd7 100644
--- a/lib/dslkeywords/file.rb
+++ b/lib/dslkeywords/file.rb
@@ -56,6 +56,11 @@ module RCM
return unless super
return evaluate_ensure_line! unless @ensure_line.nil?
+ if @is == :absent
+ ::File.delete(@file_path) if ::File.exist?(@file_path)
+ return
+ end
+
write!(real_content)
end
diff --git a/test/lib/dslkeywords/file_test.rb b/test/lib/dslkeywords/file_test.rb
index 60b659e..d8bbc49 100644
--- a/test/lib/dslkeywords/file_test.rb
+++ b/test/lib/dslkeywords/file_test.rb
@@ -24,6 +24,23 @@ class RCMFileTest < Minitest::Test
assert_equal arr.join("\n"), File.read(FILE_PATH)
end
+ def test_file_absent
+ configure_from_scratch do
+ file :create_file do
+ path FILE_PATH
+ is :present
+ :text
+ end
+
+ file :delete_file do
+ path FILE_PATH
+ is :absent
+ end
+ end
+
+ refute File.file?(FILE_PATH)
+ end
+
def test_create_file_from_sourcefile
text = 'Hello World!'
source_path = "#{FILE_PATH}.source.rcmtmp"