Permalink
Browse files

Don't load ./.pryrc when it is ~/.pryrc [Fixes #682]

  • Loading branch information...
1 parent 03dc165 commit d830ebbacc6ebaf60261855ef6011bd6b9d47d8d @ConradIrwin ConradIrwin committed Aug 5, 2012
Showing with 14 additions and 15 deletions.
  1. +6 −6 lib/pry/pry_class.rb
  2. +0 −3 test/helper.rb
  3. +8 −6 test/test_pry.rb
View
@@ -5,7 +5,7 @@
class Pry
# The RC Files to load.
- RC_FILES = ["~/.pryrc"]
+ HOME_RC_FILE = "~/.pryrc"
LOCAL_RC_FILE = "./.pryrc"
# class accessors
@@ -72,14 +72,14 @@ def self.load_file_at_toplevel(file_name)
# Load the rc files given in the `Pry::RC_FILES` array.
# This method can also be used to reload the files if they have changed.
def self.load_rc
- RC_FILES.uniq.each do |file_name|
- load_file_at_toplevel(file_name)
- end
+ load_file_at_toplevel(HOME_RC_FILE)
end
# Load the local RC file (./.pryrc)
def self.load_local_rc
- load_file_at_toplevel(LOCAL_RC_FILE)
+ unless File.expand_path(HOME_RC_FILE) == File.expand_path(LOCAL_RC_FILE)
+ load_file_at_toplevel(LOCAL_RC_FILE)
+ end
end
# Load any Ruby files specified with the -r flag on the command line.
@@ -115,7 +115,7 @@ def self.initial_session_setup
end
# Start a Pry REPL.
- # This method also loads the files specified in `Pry::RC_FILES` the
+ # This method also loads the ~/.pryrc and ./.pryrc as necessary
# first time it is invoked.
# @param [Object, Binding] target The receiver of the Pry session
# @param [Hash] options
View
@@ -18,9 +18,6 @@ def Pad.clear
# in tests)
$VERBOSE = nil
-# Ensure we do not execute any rc files
-Pry::RC_FILES.clear
-
# inject a variable into a binding
def inject_var(name, value, b)
Thread.current[:__pry_local__] = value
View
@@ -274,25 +274,26 @@ class Hello
describe "test loading rc files" do
before do
+ Pry::HOME_RC_FILE.replace File.expand_path("../testrc", __FILE__)
+ Pry::LOCAL_RC_FILE.replace File.expand_path("../testrc", __FILE__) + "/../testrc"
Pry.instance_variable_set(:@initial_session, true)
end
after do
- Pry::RC_FILES.clear
+ Pry::HOME_RC_FILE.replace "~/.pryrc"
+ Pry::LOCAL_RC_FILE.replace "./.pryrc"
Pry.config.should_load_rc = false
+ Object.remove_const(:TEST_RC) if defined?(TEST_RC)
end
- it "should run the rc file only once" do
+ it "should never run the rc file twice" do
Pry.config.should_load_rc = true
- 2.times { Pry::RC_FILES << File.expand_path("../testrc", __FILE__) }
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
TEST_RC.should == [0]
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
TEST_RC.should == [0]
-
- Object.remove_const(:TEST_RC)
end
it "should not load the pryrc if it cannot expand ENV[HOME]" do
@@ -321,8 +322,9 @@ class Hello
describe "that raise exceptions" do
before do
- Pry::RC_FILES << File.expand_path("../testrcbad", __FILE__)
+ Pry::HOME_RC_FILE = File.expand_path("../testrcbad", __FILE__)
Pry.config.should_load_rc = true
+ Pry.config.should_load_local_rc = false
putsed = nil

0 comments on commit d830ebb

Please sign in to comment.