2011-06-02 11:26:49 -04:00
|
|
|
require 'helper'
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
if !mri18_and_no_real_source_location?
|
2012-09-15 17:50:15 -04:00
|
|
|
describe "show-doc" do
|
|
|
|
before do
|
|
|
|
@o = Object.new
|
|
|
|
end
|
2012-06-11 09:36:16 -04:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
it 'should output a method\'s documentation' do
|
|
|
|
pry_eval("show-doc sample_method").should =~ /sample doc/
|
|
|
|
end
|
2011-06-02 11:26:49 -04:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
it 'should output a method\'s documentation with line numbers' do
|
|
|
|
pry_eval("show-doc sample_method -l").should =~ /\d: sample doc/
|
|
|
|
end
|
2012-01-23 08:19:26 -05:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
it 'should output a method\'s documentation with line numbers (base one)' do
|
|
|
|
pry_eval("show-doc sample_method -b").should =~ /1: sample doc/
|
|
|
|
end
|
2012-01-23 08:19:26 -05:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
it 'should output a method\'s documentation if inside method without needing to use method name' do
|
|
|
|
# sample comment
|
|
|
|
def @o.sample
|
|
|
|
pry_eval(binding, 'show-doc').should =~ /sample comment/
|
2011-06-02 11:26:49 -04:00
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
@o.sample
|
|
|
|
end
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
it "should be able to find super methods" do
|
|
|
|
c = Class.new{
|
|
|
|
# classy initialize!
|
|
|
|
def initialize(*args); end
|
|
|
|
}
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
d = Class.new(c){
|
|
|
|
# grungy initialize??
|
|
|
|
def initialize(*args, &block); end
|
|
|
|
}
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
o = d.new
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
# instancey initialize!
|
|
|
|
def o.initialize; end
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
t = pry_tester(binding)
|
2012-07-25 00:13:32 -04:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
t.eval("show-doc o.initialize").should =~ /instancey initialize/
|
|
|
|
t.eval("show-doc --super o.initialize").should =~ /grungy initialize/
|
|
|
|
t.eval("show-doc o.initialize -ss").should =~ /classy initialize/
|
2012-07-25 00:13:32 -04:00
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
begin
|
|
|
|
require 'pry-doc'
|
|
|
|
t.eval("show-doc --super o.initialize -ss").should ==
|
|
|
|
t.eval("show-doc Object#initialize")
|
|
|
|
rescue LoadError
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
2011-10-15 04:30:20 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2012-05-05 03:34:20 -04:00
|
|
|
describe "rdoc highlighting" do
|
|
|
|
it "should syntax highlight code in rdoc" do
|
|
|
|
c = Class.new{
|
|
|
|
# This can initialize your class:
|
|
|
|
#
|
|
|
|
# a = c.new :foo
|
|
|
|
#
|
|
|
|
# @param foo
|
|
|
|
def initialize(foo); end
|
|
|
|
}
|
|
|
|
|
|
|
|
begin
|
2012-07-25 00:13:32 -04:00
|
|
|
t = pry_tester(binding)
|
|
|
|
t.eval("show-doc c#initialize").should =~ /c.new :foo/
|
2012-05-05 03:34:20 -04:00
|
|
|
Pry.config.color = true
|
|
|
|
# I don't want the test to rely on which colour codes are there, just to
|
|
|
|
# assert that "something" is being colourized.
|
2012-07-25 00:13:32 -04:00
|
|
|
t.eval("show-doc c#initialize").should.not =~ /c.new :foo/
|
2012-05-05 03:34:20 -04:00
|
|
|
ensure
|
|
|
|
Pry.config.color = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should syntax highlight `code` in rdoc" do
|
|
|
|
c = Class.new{
|
|
|
|
# After initializing your class with `c.new(:foo)`, go have fun!
|
|
|
|
#
|
|
|
|
# @param foo
|
|
|
|
def initialize(foo); end
|
|
|
|
}
|
|
|
|
|
|
|
|
begin
|
2012-07-25 00:13:32 -04:00
|
|
|
t = pry_tester(binding)
|
|
|
|
t.eval("show-doc c#initialize").should =~ /c.new\(:foo\)/
|
2012-05-05 03:34:20 -04:00
|
|
|
Pry.config.color = true
|
|
|
|
# I don't want the test to rely on which colour codes are there, just to
|
|
|
|
# assert that "something" is being colourized.
|
2012-07-25 00:13:32 -04:00
|
|
|
t.eval("show-doc c#initialize").should.not =~ /c.new\(:foo\)/
|
2012-05-05 03:34:20 -04:00
|
|
|
ensure
|
|
|
|
Pry.config.color = false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not syntax highlight `` inside code" do
|
|
|
|
c = Class.new{
|
|
|
|
# Convert aligned output (from many shell commands) into nested arrays:
|
|
|
|
#
|
|
|
|
# a = decolumnize `ls -l $HOME`
|
|
|
|
#
|
|
|
|
# @param output
|
|
|
|
def decolumnize(output); end
|
|
|
|
}
|
|
|
|
|
|
|
|
begin
|
2012-07-25 00:13:32 -04:00
|
|
|
t = pry_tester(binding)
|
2012-05-05 03:34:20 -04:00
|
|
|
Pry.config.color = true
|
2012-07-25 00:13:32 -04:00
|
|
|
t.eval("show-doc c#decolumnize").should =~ /ls -l \$HOME/
|
|
|
|
t.eval("show-doc c#decolumnize").should.not =~ /`ls -l \$HOME`/
|
2012-05-05 03:34:20 -04:00
|
|
|
ensure
|
|
|
|
Pry.config.color = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-20 14:46:53 -04:00
|
|
|
describe "on sourcable objects" do
|
|
|
|
it "should show documentation for object" do
|
|
|
|
# this is a documentation
|
|
|
|
hello = proc { puts 'hello world!' }
|
|
|
|
mock_pry(binding, "show-doc hello").should =~ /this is a documentation/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
describe "on modules" do
|
|
|
|
before do
|
|
|
|
# god this is boring1
|
|
|
|
class ShowSourceTestClass
|
|
|
|
def alpha
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
# god this is boring2
|
|
|
|
module ShowSourceTestModule
|
|
|
|
def alpha
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
# god this is boring3
|
|
|
|
ShowSourceTestClassWeirdSyntax = Class.new do
|
|
|
|
def beta
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
# god this is boring4
|
|
|
|
ShowSourceTestModuleWeirdSyntax = Module.new do
|
|
|
|
def beta
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
after do
|
|
|
|
Object.remove_const :ShowSourceTestClass
|
|
|
|
Object.remove_const :ShowSourceTestClassWeirdSyntax
|
|
|
|
Object.remove_const :ShowSourceTestModule
|
|
|
|
Object.remove_const :ShowSourceTestModuleWeirdSyntax
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
describe "basic functionality, should show docs for top-level module definitions" do
|
|
|
|
it 'should show docs for a class' do
|
2012-08-04 19:33:08 -04:00
|
|
|
pry_eval("show-doc ShowSourceTestClass").should =~
|
2012-07-25 00:13:32 -04:00
|
|
|
/god this is boring1/
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
it 'should show docs for a module' do
|
2012-08-04 19:33:08 -04:00
|
|
|
pry_eval("show-doc ShowSourceTestModule").should =~
|
2012-07-25 00:13:32 -04:00
|
|
|
/god this is boring2/
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
it 'should show docs for a class when Const = Class.new syntax is used' do
|
2012-08-04 19:33:08 -04:00
|
|
|
pry_eval("show-doc ShowSourceTestClassWeirdSyntax").should =~
|
2012-07-25 00:13:32 -04:00
|
|
|
/god this is boring3/
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
it 'should show docs for a module when Const = Module.new syntax is used' do
|
2012-08-04 19:33:08 -04:00
|
|
|
pry_eval("show-doc ShowSourceTestModuleWeirdSyntax").should =~
|
2012-07-25 00:13:32 -04:00
|
|
|
/god this is boring4/
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
if !Pry::Helpers::BaseHelpers.mri_18?
|
|
|
|
describe "in REPL" do
|
|
|
|
it 'should find class defined in repl' do
|
2012-07-25 00:13:32 -04:00
|
|
|
t = pry_tester
|
|
|
|
t.eval <<-RUBY
|
|
|
|
# hello tobina
|
|
|
|
class TobinaMyDog
|
|
|
|
def woof
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
t.eval('show-doc TobinaMyDog').should =~ /hello tobina/
|
2012-04-18 02:18:33 -04:00
|
|
|
Object.remove_const :TobinaMyDog
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
end
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
it 'should lookup module name with respect to current context' do
|
|
|
|
constant_scope(:AlphaClass, :BetaClass) do
|
|
|
|
# top-level beta
|
2012-04-18 01:19:25 -04:00
|
|
|
class BetaClass
|
2012-04-18 02:18:33 -04:00
|
|
|
def alpha
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
class AlphaClass
|
|
|
|
# nested beta
|
|
|
|
class BetaClass
|
|
|
|
def beta
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2012-08-19 15:46:24 -04:00
|
|
|
pry_eval(AlphaClass, "show-doc BetaClass").should =~ /nested beta/
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
|
2012-07-25 00:13:32 -04:00
|
|
|
it 'should look up nested modules' do
|
2012-04-18 02:18:33 -04:00
|
|
|
constant_scope(:AlphaClass) do
|
|
|
|
class AlphaClass
|
|
|
|
# nested beta
|
|
|
|
class BetaClass
|
|
|
|
def beta
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-04 19:33:08 -04:00
|
|
|
pry_eval("show-doc AlphaClass::BetaClass").should =~
|
2012-07-25 00:13:32 -04:00
|
|
|
/nested beta/
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
|
2012-04-18 02:18:33 -04:00
|
|
|
describe "show-doc -a" do
|
|
|
|
it 'should show the docs for all monkeypatches defined in different files' do
|
|
|
|
# local monkeypatch
|
|
|
|
class TestClassForShowSource
|
|
|
|
def beta
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
|
2012-08-04 19:33:08 -04:00
|
|
|
result = pry_eval("show-doc TestClassForShowSource -a")
|
2012-04-18 02:18:33 -04:00
|
|
|
result.should =~ /used by/
|
|
|
|
result.should =~ /local monkeypatch/
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
2012-07-01 11:33:13 -04:00
|
|
|
|
|
|
|
describe "when no class/module arg is given" do
|
|
|
|
before do
|
2012-07-01 11:49:01 -04:00
|
|
|
module TestHost
|
2012-07-01 11:33:13 -04:00
|
|
|
|
|
|
|
# hello there froggy
|
|
|
|
module M
|
|
|
|
def d; end
|
|
|
|
def e; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2012-07-01 11:49:01 -04:00
|
|
|
Object.remove_const(:TestHost)
|
2012-07-01 11:33:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return doc for current module' do
|
2012-08-19 15:46:24 -04:00
|
|
|
pry_eval(TestHost::M, "show-doc").should =~ /hello there froggy/
|
2012-07-01 11:33:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "should skip over broken modules" do
|
|
|
|
before do
|
2012-07-01 11:49:01 -04:00
|
|
|
module TestHost
|
2012-07-01 11:33:13 -04:00
|
|
|
# hello
|
|
|
|
module M
|
|
|
|
binding.eval("def a; end", "dummy.rb", 1)
|
|
|
|
binding.eval("def b; end", "dummy.rb", 2)
|
|
|
|
binding.eval("def c; end", "dummy.rb", 3)
|
|
|
|
end
|
|
|
|
|
|
|
|
# goodbye
|
|
|
|
module M
|
|
|
|
def d; end
|
|
|
|
def e; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2012-07-01 11:49:01 -04:00
|
|
|
Object.remove_const(:TestHost)
|
2012-07-01 11:33:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return doc for first valid module' do
|
2012-08-04 19:33:08 -04:00
|
|
|
result = pry_eval("show-doc TestHost::M")
|
2012-07-25 00:13:32 -04:00
|
|
|
result.should =~ /goodbye/
|
|
|
|
result.should.not =~ /hello/
|
2012-07-01 11:33:13 -04:00
|
|
|
end
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
2012-07-01 11:33:13 -04:00
|
|
|
|
2012-08-13 23:54:07 -04:00
|
|
|
describe "on commands" do
|
|
|
|
# mostly copied & modified from test_help.rb
|
|
|
|
before do
|
|
|
|
@oldset = Pry.config.commands
|
|
|
|
@set = Pry.config.commands = Pry::CommandSet.new do
|
|
|
|
import Pry::Commands
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Pry.config.commands = @oldset
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display help for a specific command' do
|
2012-08-17 03:47:32 -04:00
|
|
|
pry_eval('show-doc ls').should =~ /Usage: ls/
|
2012-08-13 23:54:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display help for a regex command with a "listing"' do
|
|
|
|
@set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
|
2012-08-17 03:47:32 -04:00
|
|
|
pry_eval('show-doc foo').should =~ /Test listing/
|
2012-08-13 23:54:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display help for a command with a spaces in its name' do
|
|
|
|
@set.command "command with spaces", "description of a command with spaces" do; end
|
2012-08-17 03:47:32 -04:00
|
|
|
pry_eval('show-doc "command with spaces"').should =~ /description of a command with spaces/
|
2012-08-13 23:54:07 -04:00
|
|
|
end
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
2011-06-02 11:26:49 -04:00
|
|
|
end
|