summaryrefslogtreecommitdiff
path: root/test/lib/dslkeywords/directory_test.rb
blob: 41229eb87c5b5260f4eecad80ce7ea1a34849454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'minitest/autorun'
require 'fileutils'

require_relative '../../../lib/dsl'

class RCMDirectoryTest < Minitest::Test
  DIR_PATH = './.directory_test.rcmtmp'.freeze

  Minitest.after_run do
    FileUtils.rm_r(DIR_PATH) if File.directory?(DIR_PATH)
  end

  def test_create_directory
    configure_from_scratch do
      directory DIR_PATH do
        is present
      end
    end
    assert File.directory?(DIR_PATH)
  end

  def test_delete_directory
    configure_from_scratch do
      directory create do
        path DIR_PATH
        is present
      end
      directory delete do
        path DIR_PATH
        is absent
        requires directory create
      end
    end
    refute File.directory?(DIR_PATH)
  end

  def test_purge_directory
    configure_from_scratch do
      file create do
        path "#{DIR_PATH}/subdir/a_file.txt"
        manage directory
        'some content'
      end
      directory purge do
        path DIR_PATH
        without backup
        is purged
        requires file create
      end
    end
    refute File.directory?(DIR_PATH)
  end
end