2011-06-02 15:26:49 +00:00
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
describe "Pry::DefaultCommands::Documentation" do
|
|
|
|
describe "show-doc" do
|
|
|
|
it 'should output a method\'s documentation' do
|
2012-01-23 12:06:23 +00:00
|
|
|
redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), str_output=StringIO.new) do
|
2011-06-02 15:26:49 +00:00
|
|
|
pry
|
|
|
|
end
|
|
|
|
|
|
|
|
str_output.string.should =~ /sample doc/
|
|
|
|
end
|
|
|
|
|
2012-01-24 08:43:20 +00:00
|
|
|
it 'should output a method\'s documentation with line numbers' do
|
|
|
|
redirect_pry_io(InputTester.new("show-doc sample_method -l", "exit-all"), str_output=StringIO.new) do
|
2012-01-23 13:19:26 +00:00
|
|
|
pry
|
|
|
|
end
|
|
|
|
|
2012-01-24 08:43:20 +00:00
|
|
|
str_output.string.should =~ /\d: sample doc/
|
2012-01-23 13:19:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should output a method\'s documentation with line numbers (base one)' do
|
2012-01-24 08:43:20 +00:00
|
|
|
redirect_pry_io(InputTester.new("show-doc sample_method -b", "exit-all"), str_output=StringIO.new) do
|
2012-01-23 13:19:26 +00:00
|
|
|
pry
|
|
|
|
end
|
|
|
|
|
2012-01-24 08:43:20 +00:00
|
|
|
str_output.string.should =~ /1: sample doc/
|
2012-01-23 13:19:26 +00:00
|
|
|
end
|
|
|
|
|
2011-06-02 15:26:49 +00:00
|
|
|
it 'should output a method\'s documentation if inside method without needing to use method name' do
|
|
|
|
o = Object.new
|
|
|
|
|
2011-11-04 12:00:15 +00:00
|
|
|
# sample comment
|
2011-06-02 15:26:49 +00:00
|
|
|
def o.sample
|
2012-01-23 12:06:23 +00:00
|
|
|
redirect_pry_io(InputTester.new("show-doc", "exit-all"), $out=StringIO.new) do
|
2011-06-02 15:26:49 +00:00
|
|
|
binding.pry
|
|
|
|
end
|
|
|
|
end
|
|
|
|
o.sample
|
2012-01-23 12:06:23 +00:00
|
|
|
$out.string.should =~ /sample comment/
|
|
|
|
$out = nil
|
2011-06-02 15:26:49 +00:00
|
|
|
end
|
2011-10-15 08:30:20 +00:00
|
|
|
|
|
|
|
it "should be able to find super methods" do
|
|
|
|
|
|
|
|
c = Class.new{
|
|
|
|
# classy initialize!
|
|
|
|
def initialize(*args); end
|
|
|
|
}
|
|
|
|
|
|
|
|
d = Class.new(c){
|
|
|
|
# grungy initialize??
|
|
|
|
def initialize(*args, &block); end
|
|
|
|
}
|
|
|
|
|
|
|
|
o = d.new
|
|
|
|
|
|
|
|
# instancey initialize!
|
|
|
|
def o.initialize; end
|
|
|
|
|
|
|
|
mock_pry(binding, "show-doc o.initialize").should =~ /instancey initialize/
|
|
|
|
mock_pry(binding, "show-doc --super o.initialize").should =~ /grungy initialize/
|
|
|
|
mock_pry(binding, "show-doc o.initialize -ss").should =~ /classy initialize/
|
|
|
|
mock_pry(binding, "show-doc --super o.initialize -ss").should == mock_pry("show-doc Object#initialize")
|
|
|
|
end
|
2011-06-02 15:26:49 +00:00
|
|
|
end
|
|
|
|
end
|