mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Set _file_ and _line_ when calling whereami.
When a user would place a call to `binding.pry` followed by calling `whereami` the locals _file_ and _line_ would not be set properly. This commit fixes this by using the helper method `set_file_and_dir_locals()` (which also ensures _dir_ is set properly) as well as `_pry_.inject_local`. Currently the _file_ local is set to /path/to/your/directory/(pry) if the binding was set in a Pry session itself. I'm not entirely sure if this is expected behavior, if this isn't the case it shouldn't be too hard to detect and fix in a following commit. This commit fixes #574. Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
This commit is contained in:
parent
b2facc3108
commit
6b2454bde3
2 changed files with 20 additions and 3 deletions
|
@ -48,6 +48,9 @@ class Pry
|
|||
desc = (@method && @method.name_with_owner) || ""
|
||||
|
||||
if !code.empty?
|
||||
set_file_and_dir_locals(file)
|
||||
_pry_.inject_local('_line_', start, target)
|
||||
|
||||
output.puts "\n#{text.bold('From:')} #{file} @ line #{start} #{desc}:\n\n"
|
||||
output.puts code.with_line_numbers.with_marker(marker)
|
||||
output.puts
|
||||
|
|
|
@ -56,6 +56,20 @@ describe "Pry::DefaultCommands::Context" do
|
|||
Cor.new.blimey!
|
||||
Object.remove_const(:Cor)
|
||||
end
|
||||
|
||||
it 'should properly set _file_, _line_ and _dir_' do
|
||||
class Cor
|
||||
def blimey!
|
||||
mock_pry(binding, 'whereami', '_file_') \
|
||||
.should =~ /#{File.expand_path(__FILE__)}/
|
||||
|
||||
mock_pry(binding, 'whereami', '_line_').should =~ /#{__LINE__}/
|
||||
end
|
||||
end
|
||||
|
||||
Cor.new.blimey!
|
||||
Object.remove_const(:Cor)
|
||||
end
|
||||
end
|
||||
|
||||
describe "exit" do
|
||||
|
@ -160,9 +174,9 @@ describe "Pry::DefaultCommands::Context" do
|
|||
end
|
||||
|
||||
it "should not leave the REPL session when given 'cd ..'" do
|
||||
b = Pry.binding_for(Object.new)
|
||||
input = InputTester.new "cd ..", "$obj = self", "exit-all"
|
||||
|
||||
b = Pry.binding_for(Object.new)
|
||||
input = InputTester.new "cd ..", "$obj = self", "exit-all"
|
||||
|
||||
redirect_pry_io(input, StringIO.new) do
|
||||
b.pry
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue