mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Migrate test_documentation
This commit is contained in:
parent
57e7556722
commit
5f7cc2576e
3 changed files with 56 additions and 67 deletions
|
@ -276,7 +276,6 @@ class Pry
|
||||||
self.last_exception = e
|
self.last_exception = e
|
||||||
e
|
e
|
||||||
ensure
|
ensure
|
||||||
update_input_history(code)
|
|
||||||
exec_hook :after_eval, result, self
|
exec_hook :after_eval, result, self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -323,6 +322,8 @@ class Pry
|
||||||
target.eval(code, Pry.eval_path, Pry.current_line).tap do |result|
|
target.eval(code, Pry.eval_path, Pry.current_line).tap do |result|
|
||||||
set_last_result(result, target, code)
|
set_last_result(result, target, code)
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
|
update_input_history(code)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Output the result or pass to an exception handler (if result is an exception).
|
# Output the result or pass to an exception handler (if result is an exception).
|
||||||
|
|
|
@ -212,7 +212,7 @@ end
|
||||||
class PryTester
|
class PryTester
|
||||||
attr_reader :pry, :out
|
attr_reader :pry, :out
|
||||||
|
|
||||||
def initialize(context = TOPLEVEL_BINDING, *cmds)
|
def initialize(context = TOPLEVEL_BINDING)
|
||||||
@pry = Pry.new
|
@pry = Pry.new
|
||||||
|
|
||||||
if context
|
if context
|
||||||
|
|
|
@ -4,50 +4,30 @@ if !mri18_and_no_real_source_location?
|
||||||
describe "Pry::DefaultCommands::Documentation" do
|
describe "Pry::DefaultCommands::Documentation" do
|
||||||
describe "show-doc" do
|
describe "show-doc" do
|
||||||
before do
|
before do
|
||||||
@str_output = StringIO.new
|
|
||||||
@o = Object.new
|
@o = Object.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should output a method\'s documentation' do
|
it 'should output a method\'s documentation' do
|
||||||
redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), @str_output) do
|
pry_tester.eval("show-doc sample_method").should =~ /sample doc/
|
||||||
pry
|
|
||||||
end
|
|
||||||
|
|
||||||
@str_output.string.should =~ /sample doc/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should output a method\'s documentation with line numbers' do
|
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) do
|
pry_tester.eval("show-doc sample_method -l").should =~ /\d: sample doc/
|
||||||
pry
|
|
||||||
end
|
|
||||||
|
|
||||||
@str_output.string.should =~ /\d: sample doc/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should output a method\'s documentation with line numbers (base one)' do
|
it 'should output a method\'s documentation with line numbers (base one)' do
|
||||||
redirect_pry_io(InputTester.new("show-doc sample_method -b", "exit-all"), @str_output) do
|
pry_tester.eval("show-doc sample_method -b").should =~ /1: sample doc/
|
||||||
pry
|
|
||||||
end
|
|
||||||
|
|
||||||
@str_output.string.should =~ /1: sample doc/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should output a method\'s documentation if inside method without needing to use method name' do
|
it 'should output a method\'s documentation if inside method without needing to use method name' do
|
||||||
Pad.str_output = @str_output
|
|
||||||
|
|
||||||
# sample comment
|
# sample comment
|
||||||
def @o.sample
|
def @o.sample
|
||||||
redirect_pry_io(InputTester.new("show-doc", "exit-all"), Pad.str_output) do
|
pry_tester(binding).eval('show-doc').should =~ /sample comment/
|
||||||
binding.pry
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@o.sample
|
@o.sample
|
||||||
|
|
||||||
Pad.str_output.string.should =~ /sample comment/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to find super methods" do
|
it "should be able to find super methods" do
|
||||||
|
|
||||||
c = Class.new{
|
c = Class.new{
|
||||||
# classy initialize!
|
# classy initialize!
|
||||||
def initialize(*args); end
|
def initialize(*args); end
|
||||||
|
@ -63,10 +43,18 @@ if !mri18_and_no_real_source_location?
|
||||||
# instancey initialize!
|
# instancey initialize!
|
||||||
def o.initialize; end
|
def o.initialize; end
|
||||||
|
|
||||||
mock_pry(binding, "show-doc o.initialize").should =~ /instancey initialize/
|
t = pry_tester(binding)
|
||||||
mock_pry(binding, "show-doc --super o.initialize").should =~ /grungy initialize/
|
|
||||||
mock_pry(binding, "show-doc o.initialize -ss").should =~ /classy initialize/
|
t.eval("show-doc o.initialize").should =~ /instancey initialize/
|
||||||
mock_pry(binding, "show-doc --super o.initialize -ss").should == mock_pry("show-doc Object#initialize")
|
t.eval("show-doc --super o.initialize").should =~ /grungy initialize/
|
||||||
|
t.eval("show-doc o.initialize -ss").should =~ /classy initialize/
|
||||||
|
|
||||||
|
begin
|
||||||
|
require 'pry-doc'
|
||||||
|
t.eval("show-doc --super o.initialize -ss").should ==
|
||||||
|
t.eval("show-doc Object#initialize")
|
||||||
|
rescue LoadError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,11 +70,12 @@ if !mri18_and_no_real_source_location?
|
||||||
}
|
}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
mock_pry(binding, "show-doc c#initialize").should =~ /c.new :foo/
|
t = pry_tester(binding)
|
||||||
|
t.eval("show-doc c#initialize").should =~ /c.new :foo/
|
||||||
Pry.config.color = true
|
Pry.config.color = true
|
||||||
# I don't want the test to rely on which colour codes are there, just to
|
# I don't want the test to rely on which colour codes are there, just to
|
||||||
# assert that "something" is being colourized.
|
# assert that "something" is being colourized.
|
||||||
mock_pry(binding, "show-doc c#initialize").should.not =~ /c.new :foo/
|
t.eval("show-doc c#initialize").should.not =~ /c.new :foo/
|
||||||
ensure
|
ensure
|
||||||
Pry.config.color = false
|
Pry.config.color = false
|
||||||
end
|
end
|
||||||
|
@ -101,11 +90,12 @@ if !mri18_and_no_real_source_location?
|
||||||
}
|
}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
mock_pry(binding, "show-doc c#initialize").should =~ /c.new\(:foo\)/
|
t = pry_tester(binding)
|
||||||
|
t.eval("show-doc c#initialize").should =~ /c.new\(:foo\)/
|
||||||
Pry.config.color = true
|
Pry.config.color = true
|
||||||
# I don't want the test to rely on which colour codes are there, just to
|
# I don't want the test to rely on which colour codes are there, just to
|
||||||
# assert that "something" is being colourized.
|
# assert that "something" is being colourized.
|
||||||
mock_pry(binding, "show-doc c#initialize").should.not =~ /c.new\(:foo\)/
|
t.eval("show-doc c#initialize").should.not =~ /c.new\(:foo\)/
|
||||||
ensure
|
ensure
|
||||||
Pry.config.color = false
|
Pry.config.color = false
|
||||||
end
|
end
|
||||||
|
@ -123,9 +113,10 @@ if !mri18_and_no_real_source_location?
|
||||||
}
|
}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
t = pry_tester(binding)
|
||||||
Pry.config.color = true
|
Pry.config.color = true
|
||||||
mock_pry(binding, "show-doc c#decolumnize").should =~ /ls -l \$HOME/
|
t.eval("show-doc c#decolumnize").should =~ /ls -l \$HOME/
|
||||||
mock_pry(binding, "show-doc c#decolumnize").should.not =~ /`ls -l \$HOME`/
|
t.eval("show-doc c#decolumnize").should.not =~ /`ls -l \$HOME`/
|
||||||
ensure
|
ensure
|
||||||
Pry.config.color = false
|
Pry.config.color = false
|
||||||
end
|
end
|
||||||
|
@ -176,26 +167,38 @@ if !mri18_and_no_real_source_location?
|
||||||
|
|
||||||
describe "basic functionality, should show docs for top-level module definitions" do
|
describe "basic functionality, should show docs for top-level module definitions" do
|
||||||
it 'should show docs for a class' do
|
it 'should show docs for a class' do
|
||||||
mock_pry("show-doc ShowSourceTestClass").should =~ /god this is boring1/
|
pry_tester.eval("show-doc ShowSourceTestClass").should =~
|
||||||
|
/god this is boring1/
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should show docs for a module' do
|
it 'should show docs for a module' do
|
||||||
mock_pry("show-doc ShowSourceTestModule").should =~ /god this is boring2/
|
pry_tester.eval("show-doc ShowSourceTestModule").should =~
|
||||||
|
/god this is boring2/
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should show docs for a class when Const = Class.new syntax is used' do
|
it 'should show docs for a class when Const = Class.new syntax is used' do
|
||||||
mock_pry("show-doc ShowSourceTestClassWeirdSyntax").should =~ /god this is boring3/
|
pry_tester.eval("show-doc ShowSourceTestClassWeirdSyntax").should =~
|
||||||
|
/god this is boring3/
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should show docs for a module when Const = Module.new syntax is used' do
|
it 'should show docs for a module when Const = Module.new syntax is used' do
|
||||||
mock_pry("show-doc ShowSourceTestModuleWeirdSyntax").should =~ /god this is boring4/
|
pry_tester.eval("show-doc ShowSourceTestModuleWeirdSyntax").should =~
|
||||||
|
/god this is boring4/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if !Pry::Helpers::BaseHelpers.mri_18?
|
if !Pry::Helpers::BaseHelpers.mri_18?
|
||||||
describe "in REPL" do
|
describe "in REPL" do
|
||||||
it 'should find class defined in repl' do
|
it 'should find class defined in repl' do
|
||||||
mock_pry("# hello tobina", "class TobinaMyDog", "def woof", "end", "end", "show-doc TobinaMyDog").should =~ /hello tobina/
|
t = pry_tester
|
||||||
|
t.eval <<-RUBY
|
||||||
|
# hello tobina
|
||||||
|
class TobinaMyDog
|
||||||
|
def woof
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
t.eval('show-doc TobinaMyDog').should =~ /hello tobina/
|
||||||
Object.remove_const :TobinaMyDog
|
Object.remove_const :TobinaMyDog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -203,7 +206,6 @@ if !mri18_and_no_real_source_location?
|
||||||
|
|
||||||
it 'should lookup module name with respect to current context' do
|
it 'should lookup module name with respect to current context' do
|
||||||
constant_scope(:AlphaClass, :BetaClass) do
|
constant_scope(:AlphaClass, :BetaClass) do
|
||||||
|
|
||||||
# top-level beta
|
# top-level beta
|
||||||
class BetaClass
|
class BetaClass
|
||||||
def alpha
|
def alpha
|
||||||
|
@ -211,7 +213,6 @@ if !mri18_and_no_real_source_location?
|
||||||
end
|
end
|
||||||
|
|
||||||
class AlphaClass
|
class AlphaClass
|
||||||
|
|
||||||
# nested beta
|
# nested beta
|
||||||
class BetaClass
|
class BetaClass
|
||||||
def beta
|
def beta
|
||||||
|
@ -219,18 +220,14 @@ if !mri18_and_no_real_source_location?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_pry_io(InputTester.new("show-doc BetaClass", "exit-all"), outp=StringIO.new) do
|
pry_tester(AlphaClass).eval("show-doc BetaClass").should =~
|
||||||
AlphaClass.pry
|
/nested beta/
|
||||||
end
|
|
||||||
|
|
||||||
outp.string.should =~ /nested beta/
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should lookup nested modules' do
|
it 'should look up nested modules' do
|
||||||
constant_scope(:AlphaClass) do
|
constant_scope(:AlphaClass) do
|
||||||
class AlphaClass
|
class AlphaClass
|
||||||
|
|
||||||
# nested beta
|
# nested beta
|
||||||
class BetaClass
|
class BetaClass
|
||||||
def beta
|
def beta
|
||||||
|
@ -238,20 +235,20 @@ if !mri18_and_no_real_source_location?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mock_pry("show-doc AlphaClass::BetaClass").should =~ /nested beta/
|
pry_tester.eval("show-doc AlphaClass::BetaClass").should =~
|
||||||
|
/nested beta/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "show-doc -a" do
|
describe "show-doc -a" do
|
||||||
it 'should show the docs for all monkeypatches defined in different files' do
|
it 'should show the docs for all monkeypatches defined in different files' do
|
||||||
|
|
||||||
# local monkeypatch
|
# local monkeypatch
|
||||||
class TestClassForShowSource
|
class TestClassForShowSource
|
||||||
def beta
|
def beta
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
result = mock_pry("show-doc TestClassForShowSource -a")
|
result = pry_tester.eval("show-doc TestClassForShowSource -a")
|
||||||
result.should =~ /used by/
|
result.should =~ /used by/
|
||||||
result.should =~ /local monkeypatch/
|
result.should =~ /local monkeypatch/
|
||||||
end
|
end
|
||||||
|
@ -274,11 +271,8 @@ if !mri18_and_no_real_source_location?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return doc for current module' do
|
it 'should return doc for current module' do
|
||||||
redirect_pry_io(InputTester.new("show-doc"), out = StringIO.new) do
|
pry_tester(TestHost::M).eval("show-doc").should =~
|
||||||
Pry.start(TestHost::M)
|
/hello there froggy/
|
||||||
end
|
|
||||||
|
|
||||||
out.string.should =~ /hello there froggy/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -287,7 +281,6 @@ if !mri18_and_no_real_source_location?
|
||||||
describe "should skip over broken modules" do
|
describe "should skip over broken modules" do
|
||||||
before do
|
before do
|
||||||
module TestHost
|
module TestHost
|
||||||
|
|
||||||
# hello
|
# hello
|
||||||
module M
|
module M
|
||||||
binding.eval("def a; end", "dummy.rb", 1)
|
binding.eval("def a; end", "dummy.rb", 1)
|
||||||
|
@ -308,16 +301,11 @@ if !mri18_and_no_real_source_location?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return doc for first valid module' do
|
it 'should return doc for first valid module' do
|
||||||
redirect_pry_io(InputTester.new("show-doc TestHost::M"), out = StringIO.new) do
|
result = pry_tester.eval("show-doc TestHost::M")
|
||||||
Pry.start
|
result.should =~ /goodbye/
|
||||||
end
|
result.should.not =~ /hello/
|
||||||
|
|
||||||
out.string.should =~ /goodbye/
|
|
||||||
out.string.should.not =~ /hello/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue