summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJosh Cheek <josh.cheek@gmail.com>2019-06-02 00:51:17 -0500
committerKyrylo Silin <silin@kyrylo.org>2019-06-02 08:51:17 +0300
commit29bdd2e403c3d7e30435a6acc1f66689dd32f4a8 (patch)
tree3685098f5865a2c34bd5dfc8df903f1c08d49406 /spec
parent54b078b9e8b932fd19fa15947996a58cc9f11b55 (diff)
downloadpry-29bdd2e403c3d7e30435a6acc1f66689dd32f4a8.tar.gz
Fix tests that fail based on user's environment (#2047)
These tests would fail on my machine. I think it is because I have a ~/.pry_history file. I modified them to not depend on the state of my machine.
Diffstat (limited to 'spec')
-rw-r--r--spec/history_spec.rb28
1 files changed, 18 insertions, 10 deletions
diff --git a/spec/history_spec.rb b/spec/history_spec.rb
index 32eadfb3..bc3de4dd 100644
--- a/spec/history_spec.rb
+++ b/spec/history_spec.rb
@@ -22,27 +22,35 @@ RSpec.describe Pry::History do
end
describe ".default_file" do
+ let(:xdg_name) { 'XDG_DATA_HOME' }
+ let(:default_path) { File.expand_path '~/.pry_history' }
+
+ def stub_hist(options)
+ has_default = options.fetch :has_default
+ xdg_home = options.fetch :xdg_home
+ allow(File).to receive(:exist?) # there's a test helper hook that hits this
+ allow(File).to receive(:exist?).with(default_path).and_return(has_default)
+ allow(ENV).to receive(:[])
+ allow(ENV).to receive(:key?)
+ allow(ENV).to receive(:[]).with(xdg_name).and_return(xdg_home)
+ allow(ENV).to receive(:key?).with(xdg_name).and_return(!!xdg_home)
+ end
+
it "returns ~/.local/share/pry/pry_history" do
+ stub_hist has_default: false, xdg_home: nil
expect(described_class.default_file).to match('/.local/share/pry/pry_history')
end
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
-
it "returns ~/.pry_history" do
- expect(described_class.default_file).to match('/.pry_history')
+ stub_hist has_default: true, xdg_home: nil
+ expect(described_class.default_file).to eq default_path
end
end
context "when $XDG_DATA_HOME is defined" do
- before { ENV['XDG_DATA_HOME'] = '/my/path' }
- after { ENV['XDG_DATA_HOME'] = nil }
-
it "returns config location relative to $XDG_DATA_HOME" do
+ stub_hist has_default: false, xdg_home: '/my/path'
expect(described_class.default_file).to eq('/my/path/pry/pry_history')
end
end