mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
config: factor out 'system' to SystemCommandHandler
This commit is contained in:
parent
95d3a74e9b
commit
f89d0eccac
4 changed files with 51 additions and 8 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
15
lib/pry/system_command_handler.rb
Normal file
15
lib/pry/system_command_handler.rb
Normal file
|
@ -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
|
34
spec/system_command_handler_spec.rb
Normal file
34
spec/system_command_handler_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue