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

fixed tests (phew), migrated more code over to Pry.config, made major changes to helper.rb for tests

This commit is contained in:
John Mair 2011-05-29 01:38:00 +12:00
parent 2fe534b7e3
commit 34f63c65f6
4 changed files with 40 additions and 28 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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")

View file

@ -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