Module: Tipsy::Utils::SystemTest
Overview
Overrides file and directory methods for the test environment
Instance Attribute Summary collapse
-
#creations ⇒ Object
readonly
Returns the value of attribute creations.
-
#deletions ⇒ Object
readonly
Returns the value of attribute deletions.
Instance Method Summary collapse
-
#copy_file(source, destination) ⇒ Object
Copies from one location to another.
-
#copy_folder(dirname) ⇒ Object
Makes a matching folder in destination from source.
-
#copy_tree(src, dest) ⇒ Object
Iterate through a file tree and process each file and folder.
- #empty_dir?(path) ⇒ Boolean
- #log_action(name, action) ⇒ Object
- #make_file(path, content) ⇒ Object
-
#mkdir_p(path) ⇒ Object
Basic alias.
- #rm_rf(path) ⇒ Object
- #unlink(file) ⇒ Object
- #was_created?(path) ⇒ Boolean
- #was_deleted?(path) ⇒ Boolean
Methods included from System
#enumerate_tree, #excluded?, #excludes, #excludes=, #normalize_path, #skip_file?, #skip_path?
Instance Attribute Details
#creations ⇒ Object (readonly)
Returns the value of attribute creations.
10 11 12 |
# File 'lib/tipsy/utils/system_test.rb', line 10 def creations @creations end |
#deletions ⇒ Object (readonly)
Returns the value of attribute deletions.
10 11 12 |
# File 'lib/tipsy/utils/system_test.rb', line 10 def deletions @deletions end |
Instance Method Details
#copy_file(source, destination) ⇒ Object
Copies from one location to another
18 19 20 21 |
# File 'lib/tipsy/utils/system_test.rb', line 18 def copy_file(source, destination) return true if skip_file?(source) set_created(destination) end |
#copy_folder(dirname) ⇒ Object
Makes a matching folder in destination from source
26 27 28 29 30 |
# File 'lib/tipsy/utils/system_test.rb', line 26 def copy_folder(dirname) return true if skip_path?(dirname) log_action("create", dirname) set_created(dirname) end |
#copy_tree(src, dest) ⇒ Object
Iterate through a file tree and process each file and folder.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tipsy/utils/system_test.rb', line 64 def copy_tree(src, dest) ::Dir.foreach(src) do |file| next if excluded?(file) source = ::File.join(src, file) destination = ::File.join(dest, file) if ::File.directory?(source) copy_folder(destination) copy_tree(source, destination) else copy_file(source, destination) end end end |
#empty_dir?(path) ⇒ Boolean
55 56 57 58 59 |
# File 'lib/tipsy/utils/system_test.rb', line 55 def empty_dir?(path) ::Dir.entries(path).reject do |ent| ent == "." || ent == ".." || ent == path || was_deleted?(File.join(path, ent)) end.empty? end |
#log_action(name, action) ⇒ Object
80 81 |
# File 'lib/tipsy/utils/system_test.rb', line 80 def log_action(name, action) end |
#make_file(path, content) ⇒ Object
41 42 43 |
# File 'lib/tipsy/utils/system_test.rb', line 41 def make_file(path, content) set_created(path) end |
#mkdir_p(path) ⇒ Object
Basic alias
35 36 37 38 39 |
# File 'lib/tipsy/utils/system_test.rb', line 35 def mkdir_p(path) return true if ::File.exists?(path) log_action("create", path) set_created(path) end |
#rm_rf(path) ⇒ Object
45 46 47 48 |
# File 'lib/tipsy/utils/system_test.rb', line 45 def rm_rf(path) log_action('delete', path) set_deleted(path) end |
#unlink(file) ⇒ Object
50 51 52 53 |
# File 'lib/tipsy/utils/system_test.rb', line 50 def unlink(file) log_action('delete', file) set_deleted(file) end |
#was_created?(path) ⇒ Boolean
87 88 89 |
# File 'lib/tipsy/utils/system_test.rb', line 87 def was_created?(path) (@creations ||= []).include?(path) end |
#was_deleted?(path) ⇒ Boolean
83 84 85 |
# File 'lib/tipsy/utils/system_test.rb', line 83 def was_deleted?(path) (@deletions ||= []).include?(path) end |