Skip to content

Instantly share code, notes, and snippets.

@riywo
Created March 19, 2013 17:02
Show Gist options
  • Save riywo/5197933 to your computer and use it in GitHub Desktop.
Save riywo/5197933 to your computer and use it in GitHub Desktop.
module UserTempDir
def self.extended(example_group)
example_group.use_tempdir(example_group)
end
def self.included(example_group)
example_group.extend self
end
def use_tempdir(describe_block)
describe_block.before :all do
@old_pwd = Dir.pwd
@root_dir = Dir.mktmpdir
Dir.chdir @root_dir
end
describe_block.after :all do
FileUtils.remove_entry_secure @root_dir
Dir.chdir @old_pwd
end
end
def mkdir(dirpath)
path = "#{@root_dir}/#{dirpath}"
Dir.mkdir path unless File.exists? path
path
end
def write_file(filepath, content)
path = "#{@root_dir}/#{filepath}"
open(path, "w") do |f|
f.puts content
end
path
end
end
RSpec.configure do |config|
config.include UserTempDir
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment