2018-09-12 10:21:24 -04:00
|
|
|
# frozen_string_literal: true
|
2018-09-12 09:15:43 -04:00
|
|
|
|
2015-06-06 18:29:47 -04:00
|
|
|
module MutantSpec
|
|
|
|
class FileState
|
|
|
|
DEFAULTS = IceNine.deep_freeze(
|
|
|
|
file: false,
|
|
|
|
contents: nil,
|
|
|
|
requires: []
|
|
|
|
)
|
|
|
|
|
|
|
|
include Adamantium, Anima.new(*DEFAULTS.keys)
|
|
|
|
|
|
|
|
def self.new(attributes = DEFAULTS)
|
|
|
|
super(DEFAULTS.merge(attributes))
|
|
|
|
end
|
|
|
|
|
|
|
|
DOES_NOT_EXIST = new
|
|
|
|
|
|
|
|
alias_method :file?, :file
|
|
|
|
end # FileState
|
|
|
|
|
|
|
|
class FakePathname
|
|
|
|
include Adamantium, Concord.new(:file_system, :pathname)
|
|
|
|
|
|
|
|
def join(*arguments)
|
|
|
|
self.class.new(
|
|
|
|
file_system,
|
|
|
|
pathname.join(*arguments)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def read
|
|
|
|
state.contents
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
pathname.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def file?
|
|
|
|
state.file?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def state
|
|
|
|
file_system.state(pathname.to_s)
|
|
|
|
end
|
2016-04-10 17:33:47 -04:00
|
|
|
end # FakePathname
|
2015-06-06 18:29:47 -04:00
|
|
|
|
|
|
|
class FileSystem
|
|
|
|
include Adamantium, Concord.new(:file_states)
|
|
|
|
|
|
|
|
def state(filename)
|
|
|
|
file_states.fetch(filename, FileState::DOES_NOT_EXIST)
|
|
|
|
end
|
|
|
|
|
|
|
|
def path(filename)
|
|
|
|
FakePathname.new(self, Pathname.new(filename))
|
|
|
|
end
|
|
|
|
end # FileSystem
|
|
|
|
end # MutantSpec
|