lib/given_filesystem.rb in given_filesystem-0.1.2 vs lib/given_filesystem.rb in given_filesystem-0.2.0

- old
+ new

@@ -33,20 +33,23 @@ FileUtils.rm_r base_path end end end - def directory dir_name = nil + def directory user_provided_directory = nil create_random_base_path unless path_has_base? - @path_elements.push dir_name || random_name + directory_to_create = user_provided_directory || random_name + @path_elements.push directory_to_create + created_path = path FileUtils.mkdir_p created_path yield if block_given? @path_elements.pop - created_path + + File.join path, first_segment_of_path(directory_to_create) end def directory_from_data to, from = nil from ||= to @@ -107,7 +110,11 @@ @path_elements.count > 2 end def test_data_path name File.expand_path('spec/data/' + name) + end + + def first_segment_of_path path + path.split(File::SEPARATOR).reject(&:empty?).first end end