module TestConstruct::PathnameExtensions
Attributes
construct__chdir_default[RW]
construct__orig_dir[RW]
construct__root[RW]
Public Instance Methods
annotate_exception!(error)
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 77 def annotate_exception!(error) error.message << exception_message_annotation error end
chdir(&block)
click to toggle source
Note: Pathname implements chdir
directly, but it is deprecated in favor of Dir.chdir
# File lib/test_construct/pathname_extensions.rb, line 52 def chdir(&block) Dir.chdir(self, &block) end
destroy!()
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 56 def destroy! rmtree end
directory(path, opts = {}) { |subdir| ... }
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 5 def directory(path, opts = {}) chdir = opts.fetch(:chdir, construct__chdir_default) subdir = (self + path) subdir.mkpath subdir.extend(PathnameExtensions) subdir.construct__root = construct__root || self subdir.maybe_change_dir(chdir) do yield(subdir) if block_given? end subdir end
exception_message_annotation()
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 82 def exception_message_annotation "\nTestConstruct files kept at: #{self}" end
file(filepath, contents = nil, &block)
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 17 def file(filepath, contents = nil, &block) path = (self+filepath) path.dirname.mkpath mode = RUBY_PLATFORM =~ /mingw|mswin/ ? 'wb:UTF-8' : 'w' File.open(path, mode) do |f| if(block) if(block.arity==1) block.call(f) else f << block.call end else f << contents end end path end
finalize()
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 60 def finalize revert_cwd destroy! unless keep? end
keep()
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 65 def keep if construct__root construct__root.keep else @keep = true end end
keep?()
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 73 def keep? defined?(@keep) && @keep end
maybe_change_dir(chdir, &block)
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 35 def maybe_change_dir(chdir, &block) if(chdir) self.construct__orig_dir ||= Pathname.pwd self.chdir(&block) else block.call if block end end
revert_cwd()
click to toggle source
# File lib/test_construct/pathname_extensions.rb, line 44 def revert_cwd if construct__orig_dir Dir.chdir(construct__orig_dir) end end