summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-05-03 02:25:25 +0300
committerKyrylo Silin <silin@kyrylo.org>2019-05-03 02:32:29 +0300
commitd80c6517d4a601cb5eb3c2a6dfdb802f5e683a68 (patch)
treeeebcad17d225e95f4cc2d6c93a258ebb3ddb67d9 /spec
parent16fd61be2ff344e0105af1764c6e6270bb393755 (diff)
downloadpry-d80c6517d4a601cb5eb3c2a6dfdb802f5e683a68.tar.gz
config: add `rc_file` that allows specifying `pryrc` file
Keeping this in a constant makes it really hard to test. Moving it to the config and making it configurable seems to be sensible. Now we have a new option and a lot of tests.
Diffstat (limited to 'spec')
-rw-r--r--spec/config_spec.rb40
-rw-r--r--spec/history_spec.rb1
-rw-r--r--spec/pryrc_spec.rb6
3 files changed, 44 insertions, 3 deletions
diff --git a/spec/config_spec.rb b/spec/config_spec.rb
index 1cd9cdb2..a3d38043 100644
--- a/spec/config_spec.rb
+++ b/spec/config_spec.rb
@@ -40,6 +40,46 @@ 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) }
+
+ describe "#rc_file" do
+ context "when $PRYRC env variable is set" do
+ before { ENV['PRYRC'] = '/foo/pryrc' }
+ after { ENV.delete('PRYRC') }
+
+ it "defaults to the value of PRYRC env variable" do
+ expect(subject.rc_file).to eq('/foo/pryrc')
+ end
+ end
+
+ 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
+
+ it "defaults ~/.pryrc" do
+ expect(subject.rc_file).to eq('~/.pryrc')
+ end
+ 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)
+
+ ENV['XDG_CONFIG_HOME'] = '/xdg_home'
+ end
+
+ after { ENV.delete('XDG_CONFIG_HOME') }
+
+ it "defaults $XDG_CONFIG_HOME/pry/pryrc" do
+ expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
+ end
+ end
+ end
describe "#merge!" do
it "merges given hash with the config instance" do
diff --git a/spec/history_spec.rb b/spec/history_spec.rb
index 0e3f4b6e..43bf55a2 100644
--- a/spec/history_spec.rb
+++ b/spec/history_spec.rb
@@ -27,6 +27,7 @@ RSpec.describe Pry::History do
context "when ~/.pry_history exists" do
before do
allow(File).to receive(:exist?)
+ expect(File).to receive(:exist?)
.with(File.expand_path('~/.pry_history')).and_return(true)
end
diff --git a/spec/pryrc_spec.rb b/spec/pryrc_spec.rb
index 7bcd8a1f..338f6b7e 100644
--- a/spec/pryrc_spec.rb
+++ b/spec/pryrc_spec.rb
@@ -1,7 +1,7 @@
describe Pry do
describe 'loading rc files' do
before do
- stub_const('Pry::HOME_RC_FILE', 'spec/fixtures/testrc')
+ Pry.config.rc_file = 'spec/fixtures/testrc'
stub_const('Pry::LOCAL_RC_FILE', 'spec/fixtures/testrc/../testrc')
Pry.instance_variable_set(:@initial_session, true)
@@ -25,7 +25,7 @@ describe Pry do
# Resolving symlinks doesn't work on jruby 1.9 [jruby issue #538]
unless Pry::Helpers::Platform.jruby_19?
it "should not load the rc file twice if it's symlinked differently" do
- stub_const('Pry::HOME_RC_FILE', 'spec/fixtures/testrc')
+ Pry.config.rc_file = 'spec/fixtures/testrc'
stub_const('Pry::LOCAL_RC_FILE', 'spec/fixtures/testlinkrc')
Pry.start(self, input: StringIO.new("exit-all\n"), output: StringIO.new)
@@ -66,7 +66,7 @@ describe Pry do
describe "that raise exceptions" do
before do
- Pry::HOME_RC_FILE.replace "spec/fixtures/testrcbad"
+ Pry.config.rc_file = 'spec/fixtures/testrcbad'
Pry.config.should_load_local_rc = false
putsed = nil