diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index 041e76e4..e2a42061 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -141,7 +141,7 @@ class Pry end def should_use_pry_doc?(meth) - Pry.has_pry_doc && is_a_c_method?(meth) + Pry.config.has_pry_doc && is_a_c_method?(meth) end def code_type_for(meth) diff --git a/test/helper.rb b/test/helper.rb index 0a7d70a1..634ae842 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -7,9 +7,23 @@ require 'bacon' # Ensure we do not execute any rc files Pry::RC_FILES.clear -Pry.color = false -Pry.pager = false -Pry.should_load_rc = false + +# in case the tests call reset_defaults, ensure we reset them to +# amended (test friendly) values +class << Pry + alias_method :orig_reset_defaults, :reset_defaults + def reset_defaults + orig_reset_defaults + + Pry.color = false + Pry.pager = false + Pry.config.should_load_rc = false + Pry.config.history.load = false + Pry.config.history.save = false + end +end + +Pry.reset_defaults # sample doc def sample_method @@ -55,13 +69,6 @@ class Module public :remove_method end -class << Pry - alias_method :orig_reset_defaults, :reset_defaults - def reset_defaults - orig_reset_defaults - Pry.color = false - end -end class InputTester def initialize(*actions) diff --git a/test/test_default_commands.rb b/test/test_default_commands.rb index 0a140a1b..5a32265a 100644 --- a/test/test_default_commands.rb +++ b/test/test_default_commands.rb @@ -8,7 +8,7 @@ describe "Pry::Commands" do describe "hist" do push_first_hist_line = lambda do |hist, line| - hist.push line while hist.empty? + hist.push line end before do @@ -82,7 +82,7 @@ describe "Pry::Commands" do str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/ end - # strangeness in this test is due to bug in Readling::HISTORY not + # strangeness in this test is due to bug in Readline::HISTORY not # always registering first line of input it 'should return first N lines in history with --head switch' do push_first_hist_line.call(@hist, "0") diff --git a/test/test_pry.rb b/test/test_pry.rb index bec86378..db689332 100644 --- a/test/test_pry.rb +++ b/test/test_pry.rb @@ -135,13 +135,18 @@ describe Pry do end describe "test loading rc files" do + + before do + Pry.instance_variable_set(:@initial_session, true) + end + after do Pry::RC_FILES.clear - Pry.should_load_rc = false + Pry.config.should_load_rc = false end it "should run the rc file only once" do - Pry.should_load_rc = true + Pry.config.should_load_rc = true Pry::RC_FILES << File.expand_path("../testrc", __FILE__) Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput) @@ -153,17 +158,17 @@ describe Pry do Object.remove_const(:TEST_RC) end - it "should not run the rc file at all if Pry.should_load_rc is false" do - Pry.should_load_rc = false + it "should not run the rc file at all if Pry.config.should_load_rc is false" do + Pry.config.should_load_rc = false Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput) Object.const_defined?(:TEST_RC).should == false end it "should not load the rc file if #repl method invoked" do - Pry.should_load_rc = true + Pry.config.should_load_rc = true Pry.new(:input => StringIO.new("exit\n"), :output => Pry::NullOutput).repl(self) Object.const_defined?(:TEST_RC).should == false - Pry.should_load_rc = false + Pry.config.should_load_rc = false end end @@ -219,10 +224,8 @@ describe Pry do val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true end end - end - describe "commands" do it 'should run a command with no parameter' do pry_tester = Pry.new @@ -492,13 +495,15 @@ describe Pry do end it 'should create a command in a nested context and that command should be accessible from the parent' do - str_input = StringIO.new("@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit") - str_output = StringIO.new - Pry.input = str_input - obj = Object.new - Pry.new(:output => str_output).repl(obj) - Pry.input = Readline - str_output.string.should =~ /@x/ + redirect_pry_io(StringIO.new, StringIO.new) do + str_input = StringIO.new("@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit") + str_output = StringIO.new + Pry.input = str_input + obj = Object.new + Pry.new(:output => str_output).repl(obj) + Pry.input = Readline + str_output.string.should =~ /@x/ + end end it 'should define a command that keeps its return value' do