2019-05-02 18:33:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-14 20:18:17 -04:00
|
|
|
RSpec.describe Pry::ControlDHandler do
|
|
|
|
context "when given eval string is non-empty" do
|
2019-05-04 11:09:57 -04:00
|
|
|
let(:pry_instance) do
|
|
|
|
Pry.new.tap do |p|
|
|
|
|
p.eval_string = 'hello'
|
|
|
|
end
|
|
|
|
end
|
2019-04-14 20:18:17 -04:00
|
|
|
|
|
|
|
it "clears input buffer" do
|
2019-05-04 11:09:57 -04:00
|
|
|
described_class.default(pry_instance)
|
|
|
|
expect(pry_instance.eval_string).to be_empty
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
2019-04-14 20:18:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when given eval string is empty & pry instance has one binding" do
|
2019-05-04 11:09:57 -04:00
|
|
|
let(:pry_instance) do
|
|
|
|
Pry.new.tap do |p|
|
|
|
|
p.eval_string = ''
|
|
|
|
p.binding_stack = [binding]
|
|
|
|
end
|
|
|
|
end
|
2019-04-14 20:18:17 -04:00
|
|
|
|
|
|
|
it "throws :breakout" do
|
2019-05-04 11:09:57 -04:00
|
|
|
expect { described_class.default(pry_instance) }
|
2019-04-14 20:18:17 -04:00
|
|
|
.to throw_symbol(:breakout)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "clears binding stack" do
|
2019-05-04 11:09:57 -04:00
|
|
|
expect { described_class.default(pry_instance) }
|
2019-04-14 20:18:17 -04:00
|
|
|
.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(:binding1) { binding }
|
|
|
|
let(:binding2) { binding }
|
|
|
|
let(:binding_stack) { [binding1, binding2] }
|
2012-06-16 14:12:10 -04:00
|
|
|
|
2019-04-14 20:18:17 -04:00
|
|
|
let(:pry_instance) do
|
2019-05-04 11:09:57 -04:00
|
|
|
Pry.new.tap do |p|
|
|
|
|
p.eval_string = ''
|
|
|
|
p.binding_stack = binding_stack
|
|
|
|
end
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
|
2019-04-14 20:18:17 -04:00
|
|
|
it "saves a dup of the current binding stack in the 'cd' command" do
|
2019-05-04 11:09:57 -04:00
|
|
|
described_class.default(pry_instance)
|
2019-04-29 12:21:54 -04:00
|
|
|
cd_state = pry_instance.commands['cd'].state
|
2019-04-14 20:18:17 -04:00
|
|
|
expect(cd_state.old_stack).to eq([binding1, binding2])
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
|
2019-04-14 20:18:17 -04:00
|
|
|
it "pops the binding off the stack" do
|
2019-05-04 11:09:57 -04:00
|
|
|
described_class.default(pry_instance)
|
2019-04-14 20:18:17 -04:00
|
|
|
expect(pry_instance.binding_stack).to eq([binding1])
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|