lib/buildmaster/cotta/in_memory_system.rb in BuildMaster-0.9.1 vs lib/buildmaster/cotta/in_memory_system.rb in BuildMaster-1.0.6
- old
+ new
@@ -10,31 +10,33 @@
def initialize
@executed_commands = []
@content = ""
@file_system = Hash.new
+ @file_system[nil] = DirectoryContent.new('')
@file_system[Pathname.new('/')] = DirectoryContent.new('/')
@file_system[Pathname.new('.')] = DirectoryContent.new('.')
@output_map = Hash.new
end
def shell(command)
@executed_commands.push(command)
- end
-
- def shell_output(command)
result = @output_map[command]
raise "#{command} not found in expectation" unless result
return result
end
def output_for_command(command, output)
@output_map[command] = output
end
+
+ def expect_command(command)
+ Entry.new(command)
+ end
def dir_exists?(pathname)
- content = path_content(pathname)
+ content = path_content(pathname)
return !content.nil? && content.directory?
end
def file_exists?(pathname)
content = path_content(pathname)
@@ -45,11 +47,11 @@
content = path_content(pathname)
return content.children.collect {|item| item.name}
end
def mkdir(pathname)
- path_content(pathname.parent).add(create_dir(pathname))
+ path_content!(pathname.cotta_parent).add(create_dir(pathname))
end
def io(*args)
file_content = retrieve_file_content(args[0], args[1])
return StringIO.new(file_content.content, *args[1, args.size - 1])
@@ -103,11 +105,11 @@
def gather_paths_to_create(pathname)
paths = Array.new
path_to_create = pathname
while (! dir_exists?(path_to_create))
paths.push(path_to_create)
- path_to_create = path_to_create.parent
+ path_to_create = path_to_create.cotta_parent
end
return paths
end
def create_dir(pathname)
@@ -116,20 +118,29 @@
return content
end
def create_file(pathname)
content = FileContent.new(pathname.basename.to_s)
- parent_dir = pathname.parent
+ parent_dir = pathname.cotta_parent
path_content(parent_dir).add(content)
@file_system[pathname] = content
return content
end
def path_content(pathname)
- return @file_system[pathname]
+ content = path_content!(pathname)
+ if (content.nil? && pathname.cotta_parent.nil?)
+ mkdir(pathname)
+ content = @file_system[pathname]
+ end
+ return content
end
+ def path_content!(pathname)
+ @file_system[pathname]
+ end
+
def retrieve_file_content(pathname, options)
file_content = path_content(pathname)
if (file_content.nil?)
if (options =~ /r/)
raise Errno::ENOENT.new(pathname)
@@ -139,10 +150,10 @@
return file_content
end
def delete_entry(pathname)
@file_system.delete pathname
- @file_system[pathname.parent].delete(pathname.basename.to_s)
+ @file_system[pathname.cotta_parent].delete(pathname.basename.to_s)
end
end
class DirectoryContent
\ No newline at end of file