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

Improved reload-code error messages and added tests.

This commit is contained in:
Tom Kadwill 2014-04-27 18:15:29 +01:00 committed by Ryan Fitzgerald
parent 4368445ae5
commit ae1844f40a
2 changed files with 27 additions and 1 deletions

View file

@ -19,7 +19,13 @@ class Pry
if obj_name.empty? if obj_name.empty?
# if no parameters were provided then try to reload the # if no parameters were provided then try to reload the
# current file (i.e target.eval("__FILE__")) # current file (i.e target.eval("__FILE__"))
reload_current_file if _pry_.current_context.eval("self").class == Class
@obj_name = "self"
code_object = Pry::CodeObject.lookup("self", _pry_)
reload_code_object(code_object)
else
reload_current_file
end
else else
code_object = Pry::CodeObject.lookup(obj_name, _pry_) code_object = Pry::CodeObject.lookup(obj_name, _pry_)
reload_code_object(code_object) reload_code_object(code_object)

View file

@ -0,0 +1,20 @@
require_relative '../helper'
describe "reload_code" do
describe "reload_current_file" do
it 'raises an error source code not found' do
proc do
pry_eval(
"reload-code")
end.should.raise(Pry::CommandError).message.should =~ /cannot be found on disk!/
end
it 'raises an error when class not found' do
proc do
pry_eval(
"cd Class.new(Class.new{ def goo; end; public :goo })",
"reload-code")
end.should.raise(Pry::CommandError).message.should =~ /Cannot locate self/
end
end
end