summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Kadwill <tomkadwill@gmail.com>2014-04-27 18:15:29 +0100
committerRyan Fitzgerald <rwfitzge@gmail.com>2014-04-27 14:28:09 -0700
commitae1844f40a75120a371dd4afa8f4b563d9db1379 (patch)
tree9216002f879bfd3708f6b3237fa8f7f2472de1f1
parent4368445ae5814103bc375b3a2ef165eebdacb9d9 (diff)
downloadpry-ae1844f40a75120a371dd4afa8f4b563d9db1379.tar.gz
Improved reload-code error messages and added tests.
-rw-r--r--lib/pry/commands/reload_code.rb8
-rw-r--r--spec/commands/reload_code_spec.rb20
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/pry/commands/reload_code.rb b/lib/pry/commands/reload_code.rb
index 215ef0b5..1c11a62d 100644
--- a/lib/pry/commands/reload_code.rb
+++ b/lib/pry/commands/reload_code.rb
@@ -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)
diff --git a/spec/commands/reload_code_spec.rb b/spec/commands/reload_code_spec.rb
new file mode 100644
index 00000000..32df23a2
--- /dev/null
+++ b/spec/commands/reload_code_spec.rb
@@ -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