Class: Hiiro::Effects::NullFilesystem
- Inherits:
-
Object
- Object
- Hiiro::Effects::NullFilesystem
- Defined in:
- lib/hiiro/effects.rb
Overview
In-memory filesystem double for tests. Does not touch the real filesystem. Usage:
fs = NullFilesystem.new
manager = Hiiro::TodoManager.new(fs: fs)
manager.save
assert_includes fs.writes, TodoManager::TODO_FILE
Instance Attribute Summary collapse
-
#deletes ⇒ Object
readonly
Returns the value of attribute deletes.
-
#renames ⇒ Object
readonly
Returns the value of attribute renames.
-
#writes ⇒ Object
readonly
Returns the value of attribute writes.
Instance Method Summary collapse
-
#content_at(path) ⇒ Object
Retrieve what was written to path (for assertions).
- #exist?(path) ⇒ Boolean
- #glob(pattern) ⇒ Object
-
#initialize ⇒ NullFilesystem
constructor
A new instance of NullFilesystem.
- #mkdir_p(path) ⇒ Object
- #mv(src, dst) ⇒ Object
- #read(path) ⇒ Object
- #rename(src, dst) ⇒ Object
-
#reset! ⇒ Object
Reset state between tests.
- #rm(path) ⇒ Object
- #write(path, content) ⇒ Object
Constructor Details
#initialize ⇒ NullFilesystem
Returns a new instance of NullFilesystem.
104 105 106 107 108 109 |
# File 'lib/hiiro/effects.rb', line 104 def initialize @store = {} # path → content @writes = [] @deletes = [] @renames = [] end |
Instance Attribute Details
#deletes ⇒ Object (readonly)
Returns the value of attribute deletes.
102 103 104 |
# File 'lib/hiiro/effects.rb', line 102 def deletes @deletes end |
#renames ⇒ Object (readonly)
Returns the value of attribute renames.
102 103 104 |
# File 'lib/hiiro/effects.rb', line 102 def renames @renames end |
#writes ⇒ Object (readonly)
Returns the value of attribute writes.
102 103 104 |
# File 'lib/hiiro/effects.rb', line 102 def writes @writes end |
Instance Method Details
#content_at(path) ⇒ Object
Retrieve what was written to path (for assertions).
139 140 141 |
# File 'lib/hiiro/effects.rb', line 139 def content_at(path) @store[path] end |
#exist?(path) ⇒ Boolean
120 |
# File 'lib/hiiro/effects.rb', line 120 def exist?(path) = @store.key?(path) |
#glob(pattern) ⇒ Object
122 |
# File 'lib/hiiro/effects.rb', line 122 def glob(pattern) = @store.keys.select { |k| File.fnmatch(pattern, k) } |
#mkdir_p(path) ⇒ Object
121 |
# File 'lib/hiiro/effects.rb', line 121 def mkdir_p(path) = nil |
#mv(src, dst) ⇒ Object
129 130 131 132 |
# File 'lib/hiiro/effects.rb', line 129 def mv(src, dst) @store[dst] = @store.delete(src) @renames << [src, dst] end |
#read(path) ⇒ Object
116 117 118 |
# File 'lib/hiiro/effects.rb', line 116 def read(path) @store.fetch(path) { raise Errno::ENOENT, path } end |
#rename(src, dst) ⇒ Object
134 135 136 |
# File 'lib/hiiro/effects.rb', line 134 def rename(src, dst) mv(src, dst) end |
#reset! ⇒ Object
Reset state between tests.
144 145 146 147 148 149 |
# File 'lib/hiiro/effects.rb', line 144 def reset! @store = {} @writes = [] @deletes = [] @renames = [] end |
#rm(path) ⇒ Object
124 125 126 127 |
# File 'lib/hiiro/effects.rb', line 124 def rm(path) @deletes << path @store.delete(path) end |
#write(path, content) ⇒ Object
111 112 113 114 |
# File 'lib/hiiro/effects.rb', line 111 def write(path, content) @writes << path @store[path] = content end |