summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-04-15 02:34:44 +0300
committerKyrylo Silin <silin@kyrylo.org>2019-04-15 02:36:01 +0300
commitf89d0eccacd7f6a20f9ee3ca9b47a5d90e0c06e3 (patch)
tree5ce380d497ba3fb9558e738203514ad7c28851ae
parent95d3a74e9b22c44ea48ce870171640f0471db09b (diff)
downloadpry-f89d0eccacd7f6a20f9ee3ca9b47a5d90e0c06e3.tar.gz
config: factor out 'system' to SystemCommandHandler
-rw-r--r--lib/pry.rb1
-rw-r--r--lib/pry/config.rb9
-rw-r--r--lib/pry/system_command_handler.rb15
-rw-r--r--spec/system_command_handler_spec.rb34
4 files changed, 51 insertions, 8 deletions
diff --git a/lib/pry.rb b/lib/pry.rb
index 1c972b7d..f16c8e8c 100644
--- a/lib/pry.rb
+++ b/lib/pry.rb
@@ -22,6 +22,7 @@ require 'pry/editor'
require 'pry/history'
require 'pry/color_printer'
require 'pry/exception_handler'
+require 'pry/system_command_handler'
Pry::Commands = Pry::CommandSet.new unless defined?(Pry::Commands)
diff --git a/lib/pry/config.rb b/lib/pry/config.rb
index 6fcf9920..be011505 100644
--- a/lib/pry/config.rb
+++ b/lib/pry/config.rb
@@ -34,14 +34,7 @@ class Pry
# sessions.
hooks: Pry::Hooks.default,
pager: true,
-
- system: proc do |output, cmd, _|
- next if system(cmd)
-
- output.puts 'Error: there was a problem executing system ' \
- "command: #{cmd}"
- end,
-
+ system: Pry::SystemCommandHandler.method(:default),
color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
default_window_size: 5,
editor: Pry::Editor.default,
diff --git a/lib/pry/system_command_handler.rb b/lib/pry/system_command_handler.rb
new file mode 100644
index 00000000..24bea2e3
--- /dev/null
+++ b/lib/pry/system_command_handler.rb
@@ -0,0 +1,15 @@
+class Pry
+ # @api private
+ # @since ?.?.?
+ module SystemCommandHandler
+ class << self
+ def default(output, command, _pry_instance)
+ return if Kernel.system(command)
+
+ output.puts(
+ "Error: there was a problem executing system command: #{command}"
+ )
+ end
+ end
+ end
+end
diff --git a/spec/system_command_handler_spec.rb b/spec/system_command_handler_spec.rb
new file mode 100644
index 00000000..810fd606
--- /dev/null
+++ b/spec/system_command_handler_spec.rb
@@ -0,0 +1,34 @@
+require 'stringio'
+
+RSpec.describe Pry::SystemCommandHandler do
+ describe ".default" do
+ let(:output) { StringIO.new }
+ let(:pry_instance) { Pry.new }
+
+ before { allow(Kernel).to receive(:system) }
+
+ context "when command exists" do
+ before do
+ expect(Kernel).to receive(:system).with('test-command').and_return(true)
+ end
+
+ it "executes the command without printing the warning" do
+ described_class.default(output, 'test-command', pry_instance)
+ expect(output.string).to be_empty
+ end
+ end
+
+ context "when doesn't exist" do
+ before do
+ allow(Kernel).to receive(:system).with('test-command').and_return(nil)
+ end
+
+ it "executes the command without printing the warning" do
+ described_class.default(output, 'test-command', pry_instance)
+ expect(output.string).to eq(
+ "Error: there was a problem executing system command: test-command\n"
+ )
+ end
+ end
+ end
+end