diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2019-06-09 16:17:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-09 16:17:02 +0300 |
commit | 17bdfd7082e66c3d2ea0d97b26d122f6e80e0050 (patch) | |
tree | 0d8682f966e65db7432a83714542b63767c2e788 | |
parent | 6cc6e55f205c421ca6ca010a8afcafc3ed7dc299 (diff) | |
parent | 19c51bcbd15895e8fa4eb6b3c1cbe0c726c5801c (diff) | |
download | pry-17bdfd7082e66c3d2ea0d97b26d122f6e80e0050.tar.gz |
Merge pull request #2056 from aeter/master
Close #2054 - prefer XDG_* paths (if set)
-rw-r--r-- | lib/pry/config.rb | 4 | ||||
-rw-r--r-- | lib/pry/history.rb | 6 | ||||
-rw-r--r-- | spec/config_spec.rb | 29 | ||||
-rw-r--r-- | spec/history_spec.rb | 5 |
4 files changed, 31 insertions, 13 deletions
diff --git a/lib/pry/config.rb b/lib/pry/config.rb index c42bab21..0c269f76 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -307,12 +307,12 @@ class Pry def default_rc_file if ENV.key?('PRYRC') ENV['PRYRC'] - elsif File.exist?(File.expand_path('~/.pryrc')) - '~/.pryrc' elsif ENV.key?('XDG_CONFIG_HOME') && ENV['XDG_CONFIG_HOME'] != '' # See XDG Base Directory Specification at # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html ENV['XDG_CONFIG_HOME'] + '/pry/pryrc' + elsif File.exist?(File.expand_path('~/.pryrc')) + '~/.pryrc' else '~/.config/pry/pryrc' end diff --git a/lib/pry/history.rb b/lib/pry/history.rb index 19e90454..5f9a58c3 100644 --- a/lib/pry/history.rb +++ b/lib/pry/history.rb @@ -6,12 +6,12 @@ class Pry class History def self.default_file history_file = - if File.exist?(File.expand_path('~/.pry_history')) - '~/.pry_history' - elsif ENV.key?('XDG_DATA_HOME') && ENV['XDG_DATA_HOME'] != '' + if ENV.key?('XDG_DATA_HOME') && ENV['XDG_DATA_HOME'] != '' # See XDG Base Directory Specification at # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html ENV['XDG_DATA_HOME'] + '/pry/pry_history' + elsif File.exist?(File.expand_path('~/.pry_history')) + '~/.pry_history' else '~/.local/share/pry/pry_history' end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index d42d4d1e..d2cda05e 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -67,18 +67,31 @@ RSpec.describe Pry::Config do end context "when $XDG_CONFIG_HOME is defined" do - before do - allow(File).to receive(:exist?) - expect(File).to receive(:exist?) - .with(File.expand_path('~/.pryrc')).and_return(false) + before { ENV['XDG_CONFIG_HOME'] = '/xdg_home' } + after { ENV.delete('XDG_CONFIG_HOME') } + + context "when ~/.pryrc exists" do + before do + allow(File).to receive(:exist?) + expect(File).to receive(:exist?) + .with(File.expand_path('~/.pryrc')).and_return(true) + end - ENV['XDG_CONFIG_HOME'] = '/xdg_home' + it "defaults $XDG_CONFIG_HOME/pry/pryrc" do + expect(subject.rc_file).to eq('/xdg_home/pry/pryrc') + end end - after { ENV.delete('XDG_CONFIG_HOME') } + context "when ~/.pryrc doesn't exist" do + before do + allow(File).to receive(:exist?) + expect(File).to receive(:exist?) + .with(File.expand_path('~/.pryrc')).and_return(false) + end - it "defaults $XDG_CONFIG_HOME/pry/pryrc" do - expect(subject.rc_file).to eq('/xdg_home/pry/pryrc') + it "defaults $XDG_CONFIG_HOME/pry/pryrc" do + expect(subject.rc_file).to eq('/xdg_home/pry/pryrc') + end end end end diff --git a/spec/history_spec.rb b/spec/history_spec.rb index bc3de4dd..5cf63f72 100644 --- a/spec/history_spec.rb +++ b/spec/history_spec.rb @@ -53,6 +53,11 @@ RSpec.describe Pry::History do stub_hist has_default: false, xdg_home: '/my/path' expect(described_class.default_file).to eq('/my/path/pry/pry_history') end + + it "returns config location relative to $XDG_DATA_HOME when ~/.pryrc exists" do + stub_hist has_default: true, xdg_home: '/my/path' + expect(described_class.default_file).to eq('/my/path/pry/pry_history') + end end end |