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:
parent
4368445ae5
commit
ae1844f40a
2 changed files with 27 additions and 1 deletions
|
@ -19,7 +19,13 @@ class Pry
|
|||
if obj_name.empty?
|
||||
# if no parameters were provided then try to reload the
|
||||
# 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
|
||||
code_object = Pry::CodeObject.lookup(obj_name, _pry_)
|
||||
reload_code_object(code_object)
|
||||
|
|
20
spec/commands/reload_code_spec.rb
Normal file
20
spec/commands/reload_code_spec.rb
Normal 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
|
Loading…
Reference in a new issue