Created
March 19, 2013 17:02
-
-
Save riywo/5197933 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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