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

fix a bug where "cd Hash.new" reported self as a Pry::Config in prompt.

from_hash is recursive, turning Hash values into Pry::Config objects.
fix #1724
This commit is contained in:
r-obert 2017-12-09 00:42:34 +01:00 committed by r-obert
parent cebad88656
commit 97c1493e16
3 changed files with 30 additions and 14 deletions

View file

@ -18,6 +18,13 @@ See pull request [#1694](https://github.com/pry/pry/pull/1694).
See pull request [#1701](https://github.com/pry/pry/pull/1701). See pull request [#1701](https://github.com/pry/pry/pull/1701).
#### Bug fixes
* Fix a bug where 'cd Hash.new' reported self as an instance of Pry::Config
in the prompt.
See pull request [#1723](https://github.com/pry/pry/pull/1723)
#### Pry developers #### Pry developers
* Optionally skip a spec on specific Ruby engine(s) by providing `expect_failure: [:mri, :jruby]` * Optionally skip a spec on specific Ruby engine(s) by providing `expect_failure: [:mri, :jruby]`

View file

@ -529,28 +529,28 @@ class Pry
# @return [String] The prompt. # @return [String] The prompt.
def select_prompt def select_prompt
object = current_binding.eval('self') object = current_binding.eval('self')
open_token = @indent.open_delimiters.any? ? @indent.open_delimiters.last : open_token = @indent.open_delimiters.any? ? @indent.open_delimiters.last :
@indent.stack.last @indent.stack.last
c = Pry::Config.from_hash({ c = Pry::Config.new(nil)
:object => object, c.merge!({
:nesting_level => binding_stack.size - 1, :object => object,
:open_token => open_token, :nesting_level => binding_stack.size - 1,
:session_line => Pry.history.session_line_count + 1, :open_token => open_token,
:history_line => Pry.history.history_line_count + 1, :session_line => Pry.history.session_line_count + 1,
:expr_number => input_array.count, :history_line => Pry.history.history_line_count + 1,
:_pry_ => self, :expr_number => input_array.count,
:binding_stack => binding_stack, :_pry_ => self,
:input_array => input_array, :binding_stack => binding_stack,
:eval_string => @eval_string, :input_array => input_array,
:cont => !@eval_string.empty?}) :eval_string => @eval_string,
:cont => !@eval_string.empty?
})
Pry.critical_section do Pry.critical_section do
# 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)
# Otherwise use the wait prompt (indicating multi-line expression) # Otherwise use the wait prompt (indicating multi-line expression)
else else
generate_prompt(Array(prompt).last, c) generate_prompt(Array(prompt).last, c)

View file

@ -31,6 +31,15 @@ describe "Prompts" do
expect(config._pry_.is_a?(Pry)).to eq true expect(config._pry_.is_a?(Pry)).to eq true
expect(config.object).to eq self expect(config.object).to eq self
end 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
describe "BACKWARDS COMPATIBILITY: 3 parameter prompt proc" do describe "BACKWARDS COMPATIBILITY: 3 parameter prompt proc" do