This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2538 from Mange/xdg-config-home
Add support for XDG base directory support for configuration file
- Loading branch information
Showing
7 changed files
with
174 additions
and
48 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
require 'tmpdir' | ||
require 'fileutils' | ||
require 'pathname' | ||
|
||
RSpec.shared_context "isolated home directory" do | ||
around do |ex| | ||
Dir.mktmpdir do |tmp_dir| | ||
original_home = ENV['HOME'] | ||
begin | ||
ENV['HOME'] = tmp_dir | ||
ex.call | ||
ensure | ||
ENV['HOME'] = original_home | ||
# If user running this test suite has a custom $XDG_CONFIG_HOME, also | ||
# clear that out when changing $HOME so tests don't touch the user's real | ||
# configuration files. | ||
without_env_vars "XDG_CONFIG_HOME" do | ||
with_env_vars "HOME" => tmp_dir do | ||
ex.call | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
module HomeFixtureHelpers | ||
def create_fixture_file(file_name, contents) | ||
path = Pathname.new(file_name).expand_path | ||
if !path.exist? | ||
path.dirname.mkpath | ||
# Pathname#write does not exist in all supported Ruby versions | ||
File.open(path.to_s, 'w') { |file| file << contents } | ||
else | ||
# Abort just in case we're about to destroy something important. | ||
raise "File at #{path} already exists!" | ||
end | ||
end | ||
end | ||
|
||
RSpec.configure do |c| | ||
c.include_context "isolated home directory", :isolated_home => true | ||
c.include HomeFixtureHelpers, :isolated_home => true | ||
end |