Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading pryrc in other location even if XDG env is set #2184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/pry/config.rb
Expand Up @@ -301,17 +301,18 @@ def lazy_readline
end

def default_rc_file
if (pryrc = Pry::Env['PRYRC'])
pryrc
elsif (xdg_home = Pry::Env['XDG_CONFIG_HOME'])
return Pry::Env['PRYRC'] if Pry::Env['PRYRC']

if (xdg_home = Pry::Env['XDG_CONFIG_HOME'])
# See XDG Base Directory Specification at
# https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
xdg_home + '/pry/pryrc'
elsif File.exist?(File.expand_path('~/.pryrc'))
'~/.pryrc'
else
'~/.config/pry/pryrc'
xdg_home_pryrc = xdg_home + '/pry/pryrc'
return xdg_home_pryrc if File.exist?(xdg_home_pryrc)
end

return '~/.pryrc' if File.exist?(File.expand_path('~/.pryrc'))

'~/.config/pry/pryrc'
end
end
end
54 changes: 45 additions & 9 deletions spec/config_spec.rb
Expand Up @@ -80,25 +80,61 @@
allow(File).to receive(:exist?)
end

context "and when ~/.pryrc exists" do
context "and when $XDG_CONFIG_HOME/pry/pryrc exists" do
before do
allow(File).to receive(:exist?)
.with(File.expand_path('~/.pryrc')).and_return(true)
allow(File).to receive(:exist?).and_return(true)
end

it "defaults to $XDG_CONFIG_HOME/pry/pryrc" do
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
context "and when ~/.pryrc exists" do
before do
allow(File).to receive(:exist?)
.with(File.expand_path('~/.pryrc')).and_return(true)
end

it "defaults to $XDG_CONFIG_HOME/pry/pryrc" do
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
end
end

context "and when ~/.pryrc doesn't exist" do
before do
allow(File).to receive(:exist?)
.with(File.expand_path('~/.pryrc')).and_return(false)
end

it "defaults to $XDG_CONFIG_HOME/pry/pryrc" do
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
end
end
end

context "and when ~/.pryrc doesn't exist" do
context "and when $XDG_CONFIG_HOME/pry/pryrc doesn't exist" do
before do
allow(File).to receive(:exist?)
.with(File.expand_path('~/.pryrc')).and_return(false)
.with(File.expand_path('/xdg_home/pry/pryrc'))
.and_return(false)
end

it "defaults to $XDG_CONFIG_HOME/pry/pryrc" do
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
context "and when ~/.pryrc exists" do
before do
allow(File).to receive(:exist?)
.with(File.expand_path('~/.pryrc')).and_return(true)
end

it "defaults to ~/.pryrc" do
expect(subject.rc_file).to eq('~/.pryrc')
end
end

context "and when ~/.pryrc doesn't exist" do
before do
allow(File).to receive(:exist?)
.with(File.expand_path('~/.pryrc')).and_return(false)
end

it "defaults to $XDG_CONFIG_HOME/pry/pryrc" do
expect(subject.rc_file).to eq('~/.config/pry/pryrc')
end
end
end
end
Expand Down