summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-04-10 03:10:40 +0300
committerKyrylo Silin <silin@kyrylo.org>2019-04-10 03:10:40 +0300
commite1c51d7662f91e37ff5bea76d85a8d4f3c7ce3bd (patch)
tree61f9037f774514caa491caac989f0568923e13fb /spec
parent8f98b66a1311f34385dca9a565deb0ff884f7587 (diff)
downloadpry-e1c51d7662f91e37ff5bea76d85a8d4f3c7ce3bd.tar.gz
Move history file detection to Pry::History
This makes `Pry::Config` a bit cleaner and history code is better off in `Pry::History`, since it's probably the most expected location.
Diffstat (limited to 'spec')
-rw-r--r--spec/history_spec.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/spec/history_spec.rb b/spec/history_spec.rb
index f98fae85..f69fea0c 100644
--- a/spec/history_spec.rb
+++ b/spec/history_spec.rb
@@ -1,7 +1,7 @@
require 'tempfile'
require 'rbconfig'
-describe Pry do
+RSpec.describe Pry::History do
before do
Pry.history.clear
@@ -19,6 +19,32 @@ describe Pry do
Pry.history.instance_variable_set(:@original_lines, 0)
end
+ describe ".default_file" do
+ it "returns ~/.local/share/pry/pry_history" do
+ 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?)
+ .with(File.expand_path('~/.pry_history')).and_return(true)
+ end
+
+ it "returns ~/.pry_history" do
+ expect(described_class.default_file).to match('/.pry_history')
+ 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
+ expect(described_class.default_file).to eq('/my/path/pry/pry_history')
+ end
+ end
+ end
+
describe '#push' do
it "does not record duplicated lines" do
Pry.history << '3'