summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-04-10 01:24:47 +0300
committerKyrylo Silin <silin@kyrylo.org>2019-04-10 02:18:59 +0300
commit2f30e7dc63b94a9c3e59b8bb5c9c2a869a5d6329 (patch)
tree058435bfc35c3024c42f4c18d550b201053c4a17 /spec
parentf7f05fc703d6eab387dfbf484c33ae71fa70c308 (diff)
downloadpry-2f30e7dc63b94a9c3e59b8bb5c9c2a869a5d6329.tar.gz
Move `default_editor_for_platform` to Pry::Editor
The name strongly suggests that this method belongs to `Pry::Editor` and it makes no sense to have it on `Pry` class.
Diffstat (limited to 'spec')
-rw-r--r--spec/editor_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/editor_spec.rb b/spec/editor_spec.rb
index f23d815a..ea4c31d7 100644
--- a/spec/editor_spec.rb
+++ b/spec/editor_spec.rb
@@ -16,6 +16,48 @@ describe Pry::Editor do
@editor = Pry::Editor.new(Pry.new)
end
+ describe ".default" do
+ context "when $VISUAL is defined" do
+ before { ENV['VISUAL'] = 'emacs' }
+ after { ENV['VISUAL'] = nil }
+
+ it "returns the value of $VISUAL" do
+ expect(described_class.default).to eq('emacs')
+ end
+ end
+
+ context "when $EDITOR is defined" do
+ before { ENV['EDITOR'] = 'vim' }
+ after { ENV['EDITOR'] = nil }
+
+ it "returns the value of $EDITOR" do
+ expect(described_class.default).to eq('vim')
+ end
+ end
+
+ context "when platform is Windows" do
+ before do
+ allow(Pry::Helpers::Platform).to receive(:windows?).and_return(true)
+ end
+
+ it "returns 'notepad'" do
+ expect(described_class.default).to eq('notepad')
+ end
+ end
+
+ context "when no editor is detected" do
+ before { allow(Kernel).to receive(:system) }
+
+ %w[editor nano vi].each do |text_editor_name|
+ it "shells out to find '#{text_editor_name}'" do
+ expect(Kernel).to receive(:system)
+ .with("which #{text_editor_name} > /dev/null 2>&1")
+ described_class.default
+ end
+ end
+ end
+ end
+
describe "build_editor_invocation_string", skip: !Pry::Helpers::Platform.windows? do
it 'should shell-escape files' do
invocation_str = @editor.build_editor_invocation_string(@tf_path, 5, true)