diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2019-05-04 18:09:57 +0300 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2019-05-04 23:17:59 +0300 |
commit | e6ac84e99c0e32dc2641f85945594feeaf68051b (patch) | |
tree | a6c128fc53b871f83b1b286343e47d3779fefa3e /spec/control_d_handler_spec.rb | |
parent | 8f6c792ae39d130fe132ef1d50ac9dd4a8469a6f (diff) | |
download | pry-e6ac84e99c0e32dc2641f85945594feeaf68051b.tar.gz |
control_d_handler: don't mutate eval_string within the handler
This is a preparational step for #1824
(Enabling `# frozen_string_literal: true` in `~/.pryc` crashes most operations)
Alternative to https://github.com/pry/pry/pull/2030
(config: delete the `control_d_handler` option)
We had to jump a few hoops to change how the handler works. The problem is that
mutation is the default expected behaviour. Therefore, we had to change its
API. There's no need to pass `eval_string` because `pry_instance` already has it
as an attribute.
`config.control_d_handler` is a proxy proc, to preserve backwards compatibility
with users of old signature (one known user is Pry Byebug). The handler will
emit a warning if the old signature is used.
Diffstat (limited to 'spec/control_d_handler_spec.rb')
-rw-r--r-- | spec/control_d_handler_spec.rb | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/spec/control_d_handler_spec.rb b/spec/control_d_handler_spec.rb index 5e21ccbe..030cefd6 100644 --- a/spec/control_d_handler_spec.rb +++ b/spec/control_d_handler_spec.rb @@ -1,48 +1,57 @@ RSpec.describe Pry::ControlDHandler do context "when given eval string is non-empty" do - let(:eval_string) { 'hello' } - let(:pry_instance) { Pry.new } + let(:pry_instance) do + Pry.new.tap do |p| + p.eval_string = 'hello' + end + end it "clears input buffer" do - described_class.default(eval_string, pry_instance) - expect(eval_string).to be_empty + described_class.default(pry_instance) + expect(pry_instance.eval_string).to be_empty end end context "when given eval string is empty & pry instance has one binding" do - let(:eval_string) { '' } - let(:pry_instance) { Pry.new.tap { |p| p.binding_stack = [binding] } } + let(:pry_instance) do + Pry.new.tap do |p| + p.eval_string = '' + p.binding_stack = [binding] + end + end it "throws :breakout" do - expect { described_class.default(eval_string, pry_instance) } + expect { described_class.default(pry_instance) } .to throw_symbol(:breakout) end it "clears binding stack" do - expect { described_class.default(eval_string, pry_instance) } + expect { described_class.default(pry_instance) } .to throw_symbol expect(pry_instance.binding_stack).to be_empty end end context "when given eval string is empty & pry instance has 2+ bindings" do - let(:eval_string) { '' } let(:binding1) { binding } let(:binding2) { binding } let(:binding_stack) { [binding1, binding2] } let(:pry_instance) do - Pry.new.tap { |p| p.binding_stack = binding_stack } + Pry.new.tap do |p| + p.eval_string = '' + p.binding_stack = binding_stack + end end it "saves a dup of the current binding stack in the 'cd' command" do - described_class.default(eval_string, pry_instance) + described_class.default(pry_instance) cd_state = pry_instance.commands['cd'].state expect(cd_state.old_stack).to eq([binding1, binding2]) end it "pops the binding off the stack" do - described_class.default(eval_string, pry_instance) + described_class.default(pry_instance) expect(pry_instance.binding_stack).to eq([binding1]) end end |