2018-10-28 07:02:14 -04:00
|
|
|
describe Pry::Prompt do
|
2018-11-03 09:58:16 -04:00
|
|
|
describe ".[]" do
|
|
|
|
it "accesses prompts" do
|
2018-11-15 15:17:55 -05:00
|
|
|
expect(described_class[:default]).not_to be_nil
|
2018-11-03 09:58:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".all" do
|
|
|
|
it "returns a hash with prompts" do
|
2018-11-15 15:17:55 -05:00
|
|
|
expect(described_class.all).to be_a(Hash)
|
2018-11-03 09:58:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a duplicate of original prompts" do
|
2018-11-15 15:17:55 -05:00
|
|
|
described_class.all['foobar'] = Object.new
|
|
|
|
expect(described_class['foobar']).to be_nil
|
2018-11-03 09:58:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".add" do
|
2018-11-15 15:17:55 -05:00
|
|
|
after { described_class.instance_variable_get(:@prompts).delete('my_prompt') }
|
2018-11-03 09:58:16 -04:00
|
|
|
|
|
|
|
it "adds a new prompt" do
|
2018-11-15 15:17:55 -05:00
|
|
|
described_class.add(:my_prompt)
|
2018-11-10 15:20:45 -05:00
|
|
|
expect(described_class[:my_prompt]).to be_a(described_class)
|
2018-11-03 09:58:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises error when separators.size != 2" do
|
2018-11-15 15:17:55 -05:00
|
|
|
expect { described_class.add(:my_prompt, '', [1, 2, 3]) }
|
|
|
|
.to raise_error(ArgumentError, /separators size must be 2/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises error on adding a prompt with the same name" do
|
|
|
|
described_class.add(:my_prompt)
|
|
|
|
expect { described_class.add(:my_prompt) }
|
|
|
|
.to raise_error(ArgumentError, /the 'my_prompt' prompt was already added/)
|
2018-11-03 09:58:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil" do
|
2018-11-15 15:17:55 -05:00
|
|
|
expect(described_class.add(:my_prompt)).to be_nil
|
2018-11-03 09:58:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-10 15:20:45 -05:00
|
|
|
describe "#name" do
|
|
|
|
it "returns name" do
|
|
|
|
prompt = described_class.new(:test, '', Array.new(2) { proc { '' } })
|
|
|
|
expect(prompt.name).to eq(:test)
|
2012-07-12 07:13:13 -04:00
|
|
|
end
|
2018-11-10 15:20:45 -05:00
|
|
|
end
|
2012-07-12 07:13:13 -04:00
|
|
|
|
2018-11-10 15:20:45 -05:00
|
|
|
describe "#description" do
|
|
|
|
it "returns description" do
|
|
|
|
prompt = described_class.new(:test, 'descr', Array.new(2) { proc { '' } })
|
|
|
|
expect(prompt.description).to eq('descr')
|
2012-07-12 07:13:13 -04:00
|
|
|
end
|
2018-11-10 15:20:45 -05:00
|
|
|
end
|
2012-07-12 07:13:13 -04:00
|
|
|
|
2018-11-10 15:20:45 -05:00
|
|
|
describe "#prompt_procs" do
|
|
|
|
it "returns the proc array" do
|
|
|
|
prompt_procs = [proc { '>' }, proc { '*' }]
|
|
|
|
prompt = described_class.new(:test, 'descr', prompt_procs)
|
|
|
|
expect(prompt.prompt_procs).to eq(prompt_procs)
|
2017-12-08 18:42:34 -05:00
|
|
|
end
|
2012-07-12 07:13:13 -04:00
|
|
|
end
|
|
|
|
|
2018-11-10 15:20:45 -05:00
|
|
|
describe "#wait_proc" do
|
|
|
|
it "returns the first proc" do
|
|
|
|
prompt_procs = [proc { '>' }, proc { '*' }]
|
|
|
|
prompt = described_class.new(:test, '', prompt_procs)
|
|
|
|
expect(prompt.wait_proc).to eq(prompt_procs.first)
|
2012-07-12 07:13:13 -04:00
|
|
|
end
|
2018-11-10 15:20:45 -05:00
|
|
|
end
|
2012-07-12 07:13:13 -04:00
|
|
|
|
2018-11-10 15:20:45 -05:00
|
|
|
describe "#incomplete_proc" do
|
|
|
|
it "returns the second proc" do
|
|
|
|
prompt_procs = [proc { '>' }, proc { '*' }]
|
|
|
|
prompt = described_class.new(:test, '', prompt_procs)
|
|
|
|
expect(prompt.incomplete_proc).to eq(prompt_procs.last)
|
2012-07-12 07:13:13 -04:00
|
|
|
end
|
|
|
|
end
|
2018-10-28 07:02:14 -04:00
|
|
|
|
2018-11-10 15:20:45 -05:00
|
|
|
describe "prompt invocation" do
|
|
|
|
let(:pry) { Pry.new }
|
2018-10-28 07:02:14 -04:00
|
|
|
|
2018-11-10 15:20:45 -05:00
|
|
|
let(:enum) do
|
|
|
|
Enumerator.new do |y|
|
|
|
|
range = ('a'..'z').to_enum
|
|
|
|
loop { y << range.next }
|
|
|
|
end
|
2018-10-28 07:02:14 -04:00
|
|
|
end
|
|
|
|
|
2018-11-10 15:20:45 -05:00
|
|
|
it "computes prompt name dynamically" do
|
|
|
|
proc = described_class[:default].wait_proc
|
2019-03-24 20:40:05 -04:00
|
|
|
pry.config.prompt_name = Pry::Config::LazyValue.new { enum.next }
|
2018-11-10 15:20:45 -05:00
|
|
|
expect(proc.call(Object.new, 1, pry, '>')).to eq('[1] a(#<Object>):1> ')
|
|
|
|
expect(proc.call(Object.new, 1, pry, '>')).to eq('[1] b(#<Object>):1> ')
|
|
|
|
end
|
2018-10-28 07:02:14 -04:00
|
|
|
end
|
2012-07-12 07:13:13 -04:00
|
|
|
end
|