1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Simplify Prompt API

Before this change when you set a prompt, you have to do the following:

```rb
Pry.config.prompt = Pry::Prompt[:simple][:value]
```

The `[:value]` part was leaking implementation details and it proved to be an
unnecessary step.

With this change we can do the following:

```rb
Pry.config.prompt = Pry::Prompt[:simple]
```

`[:value]` is omitted.

I have also refactored some tests and removed irrelevant ones.

The Array API for prompt is deprecated:
`Pry.config.prompt = [proc {}, proc {}]` emits a warning now.
This commit is contained in:
Kyrylo Silin 2018-11-11 04:20:45 +08:00
parent 62d8ddc616
commit bc26e405ea
10 changed files with 232 additions and 164 deletions

View file

@ -110,6 +110,7 @@ require 'pry/commands'
require 'pry/plugins' require 'pry/plugins'
require 'pry/core_extensions' require 'pry/core_extensions'
require 'pry/basic_object' require 'pry/basic_object'
require "pry/prompt"
require 'pry/config/behavior' require 'pry/config/behavior'
require 'pry/config/memoization' require 'pry/config/memoization'
require 'pry/config/default' require 'pry/config/default'
@ -125,7 +126,6 @@ require 'pry/editor'
require 'pry/rubygem' require 'pry/rubygem'
require "pry/indent" require "pry/indent"
require "pry/last_exception" require "pry/last_exception"
require "pry/prompt"
require "pry/inspector" require "pry/inspector"
require 'pry/object_path' require 'pry/object_path'
require 'pry/output' require 'pry/output'

View file

@ -180,11 +180,11 @@ Pry::CLI.add_options do
end end
on "simple-prompt", "Enable simple prompt mode" do on "simple-prompt", "Enable simple prompt mode" do
Pry.config.prompt = Pry::Prompt[:simple][:value] Pry.config.prompt = Pry::Prompt[:simple]
end end
on "noprompt", "No prompt mode" do on "noprompt", "No prompt mode" do
Pry.config.prompt = Pry::Prompt[:none][:value] Pry.config.prompt = Pry::Prompt[:none]
end end
on :r, :require=, "`require` a Ruby script at startup" do |file| on :r, :require=, "`require` a Ruby script at startup" do |file|

View file

@ -25,15 +25,15 @@ class Pry::Command::ChangePrompt < Pry::ClassCommand
def list_prompts def list_prompts
prompts = Pry::Prompt.all.map do |name, prompt| prompts = Pry::Prompt.all.map do |name, prompt|
"#{bold(name)}#{red(' (selected)') if _pry_.prompt == prompt[:value]}\n" + "#{bold(name)}#{red(' (selected)') if _pry_.prompt == prompt}\n" +
prompt[:description] prompt.description
end end
output.puts(prompts.join("\n" * 2)) output.puts(prompts.join("\n" * 2))
end end
def change_prompt(prompt) def change_prompt(prompt)
if Pry::Prompt.all.key?(prompt) if Pry::Prompt[prompt]
_pry_.prompt = Pry::Prompt.all[prompt][:value] _pry_.prompt = Pry::Prompt[prompt]
else else
raise Pry::CommandError, "'#{prompt}' isn't a known prompt. " \ raise Pry::CommandError, "'#{prompt}' isn't a known prompt. " \
"Run `change-prompt --list` to see the list of known prompts." "Run `change-prompt --list` to see the list of known prompts."

View file

@ -13,7 +13,7 @@ class Pry
if state.disabled if state.disabled
state.prev_prompt = _pry_.prompt state.prev_prompt = _pry_.prompt
_pry_.prompt = Pry::Prompt[:shell][:value] _pry_.prompt = Pry::Prompt[:shell]
else else
_pry_.prompt = state.prev_prompt _pry_.prompt = state.prev_prompt
end end

View file

@ -1,8 +1,14 @@
class Pry class Pry
class Config < Pry::BasicObject class Config < Pry::BasicObject
# rubocop:disable Metrics/ModuleLength
module Behavior module Behavior
ASSIGNMENT = "=".freeze ASSIGNMENT = "=".freeze
NODUP = [TrueClass, FalseClass, NilClass, Symbol, Numeric, Module, Proc].freeze
NODUP = [
TrueClass, FalseClass, NilClass, Symbol, Numeric, Module, Proc,
Pry::Prompt
].freeze
INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/ INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/
ReservedKeyError = Class.new(RuntimeError) ReservedKeyError = Class.new(RuntimeError)
@ -251,5 +257,6 @@ class Pry
@lookup.delete(key) @lookup.delete(key)
end end
end end
# rubocop:enable Metrics/ModuleLength
end end
end end

View file

@ -18,7 +18,7 @@ class Pry
Pry::Prompt::DEFAULT_NAME Pry::Prompt::DEFAULT_NAME
}, },
prompt: proc { prompt: proc {
Pry::Prompt[:default][:value] Pry::Prompt[:default]
}, },
prompt_safe_contexts: proc { prompt_safe_contexts: proc {
Pry::Prompt::SAFE_CONTEXTS Pry::Prompt::SAFE_CONTEXTS

View file

@ -1,9 +1,9 @@
class Pry class Pry
# Prompt represents the Pry prompt, which can be used with Readline-like # Prompt represents the Pry prompt, which can be used with Readline-like
# libraries. It defines a few default prompts (default prompt, simple prompt, # libraries. It defines a few default prompts (default prompt, simple prompt,
# etc) and also provides an API to add custom prompts. # etc) and also provides an API for adding and implementing custom prompts.
# #
# @example # @example Registering a new Pry prompt
# Pry::Prompt.add( # Pry::Prompt.add(
# :ipython, # :ipython,
# 'IPython-like prompt', [':', '...:'] # 'IPython-like prompt', [':', '...:']
@ -17,9 +17,23 @@ class Pry
# # ...: end # # ...: end
# # => :foo # # => :foo
# # In [4]: # # In [4]:
#
# @example Manually instantiating the Prompt class
# prompt_procs = [
# proc { '#{rand(1)}>" },
# proc { "#{('a'..'z').to_a.sample}*" }
# ]
# prompt = Pry::Prompt.new(
# :random,
# 'Random number or letter prompt.',
# prompt_procs
# )
# prompt.wait_proc.call(...) #=>
# prompt.incomplete_proc.call(...)
#
# @since v0.11.0 # @since v0.11.0
# @api public # @api public
module Prompt class Prompt
# @return [String] # @return [String]
DEFAULT_NAME = 'pry'.freeze DEFAULT_NAME = 'pry'.freeze
@ -35,7 +49,7 @@ class Pry
# Retrieves a prompt. # Retrieves a prompt.
# #
# @example # @example
# Prompt[:my_prompt][:value] # Prompt[:my_prompt]
# #
# @param [Symbol] name The name of the prompt you want to access # @param [Symbol] name The name of the prompt you want to access
# @return [Hash{Symbol=>Object}] # @return [Hash{Symbol=>Object}]
@ -78,12 +92,13 @@ class Pry
raise ArgumentError, "the '#{name}' prompt was already added" raise ArgumentError, "the '#{name}' prompt was already added"
end end
@prompts[name] = { @prompts[name] = new(
description: description, name,
value: separators.map do |sep| description,
separators.map do |sep|
proc { |context, nesting, _pry_| yield(context, nesting, _pry_, sep) } proc { |context, nesting, _pry_| yield(context, nesting, _pry_, sep) }
end end
} )
nil nil
end end
@ -97,10 +112,63 @@ class Pry
end end
end end
add 'default', # @return [String]
"The default Pry prompt. Includes information about the current expression \n" \ attr_reader :name
"number, evaluation context, and nesting level, plus a reminder that you're \n" \
'using Pry.' do |context, nesting, _pry_, sep| # @return [String]
attr_reader :description
# @return [Array<Proc>] the array of procs that hold
# `[wait_proc, incomplete_proc]`
attr_reader :prompt_procs
# @param [String] name
# @param [String] description
# @param [Array<Proc>] prompt_procs
def initialize(name, description, prompt_procs)
@name = name
@description = description
@prompt_procs = prompt_procs
end
# @return [Proc] the proc which builds the wait prompt (`>`)
def wait_proc
@prompt_procs.first
end
# @return [Proc] the proc which builds the prompt when in the middle of an
# expression such as open method, etc. (`*`)
def incomplete_proc
@prompt_procs.last
end
# @deprecated Use a `Pry::Prompt` instance directly
def [](key)
key = key.to_s
loc = caller_locations(1..1).first
if %w[name description].include?(key)
warn(
"#{loc.path}:#{loc.lineno}: warning: `Pry::Prompt[:#{@name}][:#{key}]` " \
"is deprecated. Use `#{self.class}##{key}` instead"
)
public_send(key)
elsif key.to_s == 'value'
warn(
"#{loc.path}:#{loc.lineno}: warning: `#{self.class}[:#{@name}][:value]` " \
"is deprecated. Use `#{self.class}#prompt_procs` instead or an " \
"instance of `#{self.class}` directly"
)
@prompt_procs
end
end
add(
:default,
"The default Pry prompt. Includes information about the current expression \n" \
"number, evaluation context, and nesting level, plus a reminder that you're \n" \
'using Pry.'
) do |context, nesting, _pry_, sep|
format( format(
"[%<in_count>s] %<name>s(%<context>s)%<nesting>s%<separator>s ", "[%<in_count>s] %<name>s(%<context>s)%<nesting>s%<separator>s ",
in_count: _pry_.input_ring.count, in_count: _pry_.input_ring.count,
@ -112,7 +180,7 @@ class Pry
end end
add( add(
'simple', :simple,
"A simple `>>`.", "A simple `>>`.",
['>> ', ' | '] ['>> ', ' | ']
) do |_, _, _, sep| ) do |_, _, _, sep|
@ -120,7 +188,7 @@ class Pry
end end
add( add(
'nav', :nav,
"A prompt that displays the binding stack as a path and includes information \n" \ "A prompt that displays the binding stack as a path and includes information \n" \
"about #{Helpers::Text.bold('_in_')} and #{Helpers::Text.bold('_out_')}.", "about #{Helpers::Text.bold('_in_')} and #{Helpers::Text.bold('_out_')}.",
%w[> *] %w[> *]
@ -137,7 +205,7 @@ class Pry
end end
add( add(
'shell', :shell,
'A prompt that displays `$PWD` as you change it.', 'A prompt that displays `$PWD` as you change it.',
%w[$ *] %w[$ *]
) do |context, _nesting, _pry_, sep| ) do |context, _nesting, _pry_, sep|
@ -151,7 +219,7 @@ class Pry
end end
add( add(
'none', :none,
'Wave goodbye to the Pry prompt.', 'Wave goodbye to the Pry prompt.',
Array.new(2) Array.new(2)
) { '' } ) { '' }

View file

@ -58,7 +58,7 @@ class Pry
# The object to use for commands. # The object to use for commands.
# @option options [Hash] :hooks # @option options [Hash] :hooks
# The defined hook Procs. # The defined hook Procs.
# @option options [Array<Proc>] :prompt # @option options [Pry::Prompt] :prompt
# The array of Procs to use for prompts. # The array of Procs to use for prompts.
# @option options [Proc] :print # @option options [Proc] :print
# The Proc to use for printing return values. # The Proc to use for printing return values.
@ -85,14 +85,18 @@ class Pry
@input_ring << nil @input_ring << nil
push_initial_binding(target) push_initial_binding(target)
exec_hook(:when_started, target, options, self) exec_hook(:when_started, target, options, self)
@prompt_warn = false
end end
# This is the prompt at the top of the prompt stack. # This is the prompt at the top of the prompt stack.
# @return [Array<Proc>] the current prompt # @return [Pry::Prompt] the current prompt
def prompt def prompt
prompt_stack.last prompt_stack.last
end end
# Sets the Pry prompt.
# @param [Pry::Prompt] new_prompt
# @return [void]
def prompt=(new_prompt) def prompt=(new_prompt)
if prompt_stack.empty? if prompt_stack.empty?
push_prompt new_prompt push_prompt new_prompt
@ -548,6 +552,22 @@ class Pry
}) })
Pry.critical_section do Pry.critical_section do
# If input buffer is empty, then use normal prompt. Otherwise use the wait
# prompt (indicating multi-line expression).
if prompt.is_a?(Pry::Prompt)
prompt_proc = eval_string.empty? ? prompt.wait_proc : prompt.incomplete_proc
return prompt_proc.call(c.object, c.nesting_level, c._pry_)
end
unless @prompt_warn
@prompt_warn = true
output.warn(
"warning: setting prompt with help of " \
"`Pry.config.prompt = [proc {}, proc {}]` is deprecated. " \
"Use Pry::Prompt API instead"
)
end
# If input buffer is empty then use normal prompt # If input buffer is empty then use normal prompt
if eval_string.empty? if eval_string.empty?
generate_prompt(Array(prompt).first, c) generate_prompt(Array(prompt).first, c)
@ -575,27 +595,28 @@ class Pry
# Pushes the current prompt onto a stack that it can be restored from later. # Pushes the current prompt onto a stack that it can be restored from later.
# Use this if you wish to temporarily change the prompt. # Use this if you wish to temporarily change the prompt.
# @param [Array<Proc>] new_prompt #
# @return [Array<Proc>] new_prompt
# @example # @example
# new_prompt = [ proc { '>' }, proc { '>>' } ] # push_prompt(Pry::Prompt[:my_prompt])
# push_prompt(new_prompt) # => new_prompt #
# @param [Pry::Prompt] new_prompt
# @return [Pry::Prompt] new_prompt
def push_prompt(new_prompt) def push_prompt(new_prompt)
prompt_stack.push new_prompt prompt_stack.push new_prompt
end end
# Pops the current prompt off of the prompt stack. # Pops the current prompt off of the prompt stack. If the prompt you are
# If the prompt you are popping is the last prompt, it will not be popped. # popping is the last prompt, it will not be popped. Use this to restore the
# Use this to restore the previous prompt. # previous prompt.
# @return [Array<Proc>] Prompt being popped. #
# @example # @example
# prompt1 = [ proc { '>' }, proc { '>>' } ] # pry = Pry.new(prompt: Pry::Prompt[:my_prompt1])
# prompt2 = [ proc { '$' }, proc { '>' } ] # pry.push_prompt(Pry::Prompt[:my_prompt2])
# pry = Pry.new :prompt => prompt1
# pry.push_prompt(prompt2)
# pry.pop_prompt # => prompt2 # pry.pop_prompt # => prompt2
# pry.pop_prompt # => prompt1 # pry.pop_prompt # => prompt1
# pry.pop_prompt # => prompt1 # pry.pop_prompt # => prompt1
#
# @return [Pry::Prompt] the prompt being popped
def pop_prompt def pop_prompt
prompt_stack.size > 1 ? prompt_stack.pop : prompt prompt_stack.size > 1 ? prompt_stack.pop : prompt
end end

View file

@ -23,7 +23,7 @@ describe Pry::Prompt do
it "adds a new prompt" do it "adds a new prompt" do
described_class.add(:my_prompt) described_class.add(:my_prompt)
expect(described_class[:my_prompt]).to be_a(Hash) expect(described_class[:my_prompt]).to be_a(described_class)
end end
it "raises error when separators.size != 2" do it "raises error when separators.size != 2" do
@ -42,87 +42,59 @@ describe Pry::Prompt do
end end
end end
describe "one-parameter prompt proc" do describe "#name" do
it 'should get full config object' do it "returns name" do
config = nil prompt = described_class.new(:test, '', Array.new(2) { proc { '' } })
redirect_pry_io(InputTester.new("exit-all")) do expect(prompt.name).to eq(:test)
Pry.start(self, prompt: proc { |v| config = v })
end
expect(config.is_a?(Pry::Config)).to eq true
end
it 'should get full config object, when using a proc array' do
config1 = nil
redirect_pry_io(InputTester.new("exit-all")) do
Pry.start(self, prompt: [proc { |v| config1 = v }, proc { |v| _config2 = v }])
end
expect(config1.is_a?(Pry::Config)).to eq true
end
it 'should receive correct data in the config object' do
config = nil
redirect_pry_io(InputTester.new("def hello", "exit-all")) do
Pry.start(self, prompt: proc { |v| config = v })
end
expect(config.eval_string).to match(/def hello/)
expect(config.nesting_level).to eq 0
expect(config.expr_number).to eq 1
expect(config.cont).to eq true
expect(config._pry_.is_a?(Pry)).to eq true
expect(config.object).to eq self
end
specify "object is Hash when current binding is a Hash" do
config = nil
h = {}
redirect_pry_io(InputTester.new("exit-all")) do
Pry.start(h, prompt: proc { |v| config = v })
end
expect(config.object).to be(h)
end end
end end
describe "BACKWARDS COMPATIBILITY: 3 parameter prompt proc" do describe "#description" do
it 'should get 3 parameters' do it "returns description" do
o = n = p = nil prompt = described_class.new(:test, 'descr', Array.new(2) { proc { '' } })
redirect_pry_io(InputTester.new("exit-all")) do expect(prompt.description).to eq('descr')
Pry.start(:test, prompt: proc { |obj, nesting, _pry_|
o, n, p = obj, nesting, _pry_ })
end
expect(o).to eq :test
expect(n).to eq 0
expect(p.is_a?(Pry)).to eq true
end
it 'should get 3 parameters, when using proc array' do
o1 = n1 = p1 = nil
redirect_pry_io(InputTester.new("exit-all")) do
Pry.start(:test, prompt: [proc { |obj, nesting, _pry_|
o1, n1, p1 = obj, nesting, _pry_ },
proc { |obj, nesting, _pry_|
_o2, _n2, _p2 = obj, nesting, _pry_ }])
end
expect(o1).to eq :test
expect(n1).to eq 0
expect(p1.is_a?(Pry)).to eq true
end end
end end
it "can compute prompt name dynamically" do describe "#prompt_procs" do
config = nil it "returns the proc array" do
redirect_pry_io(InputTester.new("def hello", "exit-all")) do prompt_procs = [proc { '>' }, proc { '*' }]
Pry.start(self, prompt: proc { |v| config = v }) prompt = described_class.new(:test, 'descr', prompt_procs)
expect(prompt.prompt_procs).to eq(prompt_procs)
end
end
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)
end
end
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)
end
end
describe "prompt invocation" do
let(:pry) { Pry.new }
let(:enum) do
Enumerator.new do |y|
range = ('a'..'z').to_enum
loop { y << range.next }
end
end end
enum = Enumerator.new do |y| it "computes prompt name dynamically" do
count = 100 proc = described_class[:default].wait_proc
loop { y << count += 1 } pry.config.prompt_name = Pry.lazy { enum.next }
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 end
config._pry_.config.prompt_name = Pry.lazy { enum.next }
proc = described_class[:default][:value].first
expect(proc.call(Object.new, 1, config._pry_)).to eq('[1] 101(#<Object>):1> ')
expect(proc.call(Object.new, 1, config._pry_)).to eq('[1] 102(#<Object>):1> ')
end end
end end

View file

@ -141,95 +141,95 @@ describe "test Pry defaults" do
end end
it 'should set the prompt default, and the default should be overridable (single prompt)' do it 'should set the prompt default, and the default should be overridable (single prompt)' do
Pry.prompt = proc { "test prompt> " } Pry.prompt = Pry::Prompt.new(:test, '', Array.new(2) { proc { '>' } })
new_prompt = proc { "A" } new_prompt = Pry::Prompt.new(:new_test, '', Array.new(2) { proc { 'A' } })
pry = Pry.new pry = Pry.new
expect(pry.prompt).to eq Pry.prompt expect(pry.prompt).to eq Pry.prompt
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt> "] expect(get_prompts(pry)).to eq(%w[> >])
pry = Pry.new(prompt: new_prompt) pry = Pry.new(prompt: new_prompt)
expect(pry.prompt).to eq new_prompt expect(pry.prompt).to eq(new_prompt)
expect(get_prompts(pry)).to eq ["A", "A"] expect(get_prompts(pry)).to eq(%w[A A])
pry = Pry.new pry = Pry.new
expect(pry.prompt).to eq Pry.prompt expect(pry.prompt).to eq Pry.prompt
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt> "] expect(get_prompts(pry)).to eq(%w[> >])
end end
it 'should set the prompt default, and the default should be overridable (multi prompt)' do it 'should set the prompt default, and the default should be overridable (multi prompt)' do
Pry.prompt = [proc { "test prompt> " }, proc { "test prompt* " }] Pry.prompt = Pry::Prompt.new(:test, '', [proc { '>' }, proc { '*' }])
new_prompt = [proc { "A" }, proc { "B" }] new_prompt = Pry::Prompt.new(:new_test, '', [proc { 'A' }, proc { 'B' }])
pry = Pry.new pry = Pry.new
expect(pry.prompt).to eq Pry.prompt expect(pry.prompt).to eq Pry.prompt
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt* "] expect(get_prompts(pry)).to eq(%w[> *])
pry = Pry.new(prompt: new_prompt) pry = Pry.new(prompt: new_prompt)
expect(pry.prompt).to eq new_prompt expect(pry.prompt).to eq(new_prompt)
expect(get_prompts(pry)).to eq ["A", "B"] expect(get_prompts(pry)).to eq(%w[A B])
pry = Pry.new pry = Pry.new
expect(pry.prompt).to eq Pry.prompt expect(pry.prompt).to eq(Pry.prompt)
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt* "] expect(get_prompts(pry)).to eq(%w[> *])
end end
describe 'storing and restoring the prompt' do describe 'storing and restoring the prompt' do
before do let(:prompt1) { Pry::Prompt.new(:test1, '', Array.new(2) { proc { '' } }) }
make = lambda do |name,i| let(:prompt2) { Pry::Prompt.new(:test2, '', Array.new(2) { proc { '' } }) }
prompt = [ proc { "#{i}>" } , proc { "#{i + 1}>" } ] let(:prompt3) { Pry::Prompt.new(:test3, '', Array.new(2) { proc { '' } }) }
(class << prompt; self; end).send(:define_method, :inspect) { "<Prompt-#{name}>" }
prompt let(:pry) { Pry.new(prompt: prompt1) }
end
@a , @b , @c = make[:a,0] , make[:b,1] , make[:c,2]
@pry = Pry.new prompt: @a
end
it 'should have a prompt stack' do it 'should have a prompt stack' do
@pry.push_prompt @b pry.push_prompt(prompt2)
@pry.push_prompt @c pry.push_prompt(prompt3)
expect(@pry.prompt).to eq @c expect(pry.prompt).to eq(prompt3)
@pry.pop_prompt pry.pop_prompt
expect(@pry.prompt).to eq @b expect(pry.prompt).to match(prompt2)
@pry.pop_prompt pry.pop_prompt
expect(@pry.prompt).to eq @a expect(pry.prompt).to eq(prompt1)
end end
it 'should restore overridden prompts when returning from file-mode' do it 'should restore overridden prompts when returning from shell-mode' do
pry = Pry.new(prompt: [ proc { 'P>' } ] * 2) pry = Pry.new(
expect(pry.select_prompt).to eq "P>" prompt: Pry::Prompt.new(:test, '', Array.new(2) { proc { 'P>' } })
)
expect(pry.select_prompt).to eq('P>')
pry.process_command('shell-mode') pry.process_command('shell-mode')
expect(pry.select_prompt).to match(/\Apry .* \$ \z/) expect(pry.select_prompt).to match(/\Apry .* \$ \z/)
pry.process_command('shell-mode') pry.process_command('shell-mode')
expect(pry.select_prompt).to eq "P>" expect(pry.select_prompt).to eq('P>')
end end
it '#pop_prompt should return the popped prompt' do it '#pop_prompt should return the popped prompt' do
@pry.push_prompt @b pry.push_prompt(prompt2)
@pry.push_prompt @c pry.push_prompt(prompt3)
expect(@pry.pop_prompt).to eq @c expect(pry.pop_prompt).to eq(prompt3)
expect(@pry.pop_prompt).to eq @b expect(pry.pop_prompt).to eq(prompt2)
end end
it 'should not pop the last prompt' do it 'should not pop the last prompt' do
@pry.push_prompt @b pry.push_prompt(prompt2)
expect(@pry.pop_prompt).to eq @b expect(pry.pop_prompt).to eq(prompt2)
expect(@pry.pop_prompt).to eq @a expect(pry.pop_prompt).to eq(prompt1)
expect(@pry.pop_prompt).to eq @a expect(pry.pop_prompt).to eq(prompt1)
expect(@pry.prompt).to eq @a expect(pry.prompt).to eq(prompt1)
end end
describe '#prompt= should replace the current prompt with the new prompt' do describe '#prompt= should replace the current prompt with the new prompt' do
it 'when only one prompt on the stack' do it 'when only one prompt on the stack' do
@pry.prompt = @b pry.prompt = prompt2
expect(@pry.prompt).to eq @b expect(pry.prompt).to eq(prompt2)
expect(@pry.pop_prompt).to eq @b expect(pry.pop_prompt).to eq(prompt2)
expect(@pry.pop_prompt).to eq @b expect(pry.pop_prompt).to eq(prompt2)
end end
it 'when several prompts on the stack' do it 'when several prompts on the stack' do
@pry.push_prompt @b pry.push_prompt(prompt2)
@pry.prompt = @c pry.prompt = prompt3
expect(@pry.pop_prompt).to eq @c expect(pry.pop_prompt).to eq(prompt3)
expect(@pry.pop_prompt).to eq @a expect(pry.pop_prompt).to eq(prompt1)
end end
end end
end end