summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorArmin <mail@arminfroehlich.de>2021-07-01 09:21:14 +0200
committerGitHub <noreply@github.com>2021-07-01 10:21:14 +0300
commitdb856653dd47995c39711f1518ebf94792e9c471 (patch)
treee430ece5c16b62ea175345d521014460a6ba3b61 /spec
parent586e1bd1502983cf52d6fd76902224b5731816e9 (diff)
downloadpry-db856653dd47995c39711f1518ebf94792e9c471.tar.gz
validates file presence in Config#default_rc_file (#2129)
* validates file presence in Config#default_rc_file Return `nil` if no default rc file is present in the filesystem. This fixes the behavior if $XDG_CONFIG_HOME is set, but no rc file at the path `$XDG_CONFIG_HOME/pry/pryrc` (while it may be at `~/.pryrc`).
Diffstat (limited to 'spec')
-rw-r--r--spec/config_spec.rb48
1 files changed, 40 insertions, 8 deletions
diff --git a/spec/config_spec.rb b/spec/config_spec.rb
index 4018a1db..28ed3def 100644
--- a/spec/config_spec.rb
+++ b/spec/config_spec.rb
@@ -41,11 +41,14 @@ RSpec.describe Pry::Config do
specify { expect(subject.history_load).to eq(true).or be(false) }
specify { expect(subject.history_file).to be_a(String) }
specify { expect(subject.exec_string).to be_a(String) }
- specify { expect(subject.rc_file).to be_a(String) }
+ specify { expect(subject.rc_file).to be_a(String).or be(nil) }
describe "#rc_file" do
context "when $PRYRC env variable is set" do
before do
+ allow(File).to receive(:exist?)
+ allow(File).to receive(:exist?)
+ .with('/foo/pryrc').and_return(true)
allow(Pry::Env).to receive(:[])
allow(Pry::Env).to receive(:[]).with('PRYRC').and_return('/foo/pryrc')
end
@@ -67,7 +70,7 @@ RSpec.describe Pry::Config do
end
it "defaults to ~/.pryrc" do
- expect(subject.rc_file).to eq('~/.pryrc')
+ expect(subject.rc_file).to eq(File.expand_path('~/.pryrc'))
end
end
@@ -76,29 +79,58 @@ RSpec.describe Pry::Config do
allow(Pry::Env).to receive(:[])
allow(Pry::Env).to receive(:[])
.with('XDG_CONFIG_HOME').and_return('/xdg_home')
+ end
- allow(File).to receive(:exist?)
+ context "and when '/xdg_home/pry/pryrc' exists" do
+ before do
+ allow(File).to receive(:exist?)
+ allow(File).to receive(:exist?)
+ .with('/xdg_home/pry/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 exists" do
before do
allow(File).to receive(:exist?)
+ 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')
+ it "defaults to ~/.pryrc" do
+ expect(subject.rc_file).to eq(File.expand_path('~/.pryrc'))
+ end
+
+ context "and when ~/.config/pry/pryrc exists" do
+ before do
+ allow(File).to receive(:exist?)
+ allow(File).to receive(:exist?)
+ .with(File.expand_path('~/.config/pry/pryrc')).and_return(true)
+ end
+
+ it "defaults to ~/.config/pry/pryrc" do
+ expect(subject.rc_file).to eq(File.expand_path('~/.config/pry/pryrc'))
+ end
end
end
- context "and when ~/.pryrc doesn't exist" do
+ context "and when no default rc file exists" do
before do
allow(File).to receive(:exist?)
+ allow(Pry::Env).to receive(:[]).with('PRYRC').and_return(nil)
+ allow(File).to receive(:exist?)
+ .with('/xdg_home/pry/pryrc').and_return(false)
+ allow(File).to receive(:exist?)
.with(File.expand_path('~/.pryrc')).and_return(false)
+ allow(File).to receive(:exist?)
+ .with(File.expand_path('~/.config/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')
+ it "should return nil" do
+ expect(subject.rc_file).to eq(nil)
end
end
end