2014-03-14 00:31:24 -04:00
|
|
|
require_relative '../helper'
|
2012-12-06 19:52:37 -05:00
|
|
|
require "fixtures/show_source_doc_examples"
|
2011-06-02 11:26:49 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "show-doc" do
|
|
|
|
before do
|
|
|
|
@o = Object.new
|
2012-06-11 09:36:16 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# sample doc
|
|
|
|
def @o.sample_method
|
|
|
|
:sample
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
2011-06-02 11:26:49 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
def @o.no_docs;end
|
2012-01-23 08:19:26 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should output a method\'s documentation' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval(binding, "show-doc @o.sample_method")).to match(/sample doc/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-03-27 17:45:05 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should raise exception when cannot find docs' do
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { pry_eval(binding, "show-doc @o.no_docs") }.to raise_error Pry::CommandError
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-03-27 17:45:05 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should output a method\'s documentation with line numbers' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval(binding, "show-doc @o.sample_method -l")).to match(/\d: sample doc/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-03-27 17:45:05 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should output a method\'s documentation with line numbers (base one)' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval(binding, "show-doc @o.sample_method -b")).to match(/1: sample doc/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-03-27 17:45:05 -04:00
|
|
|
|
2013-10-24 01:58:26 -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/
|
|
|
|
end
|
|
|
|
@o.sample
|
|
|
|
end
|
2012-12-21 10:39:57 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "finding find super method docs with help of `--super` switch" do
|
|
|
|
before do
|
|
|
|
class Daddy
|
|
|
|
# daddy initialize!
|
|
|
|
def initialize(*args); end
|
2013-03-27 17:45:05 -04:00
|
|
|
end
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
class Classy < Daddy
|
|
|
|
# classy initialize!
|
|
|
|
def initialize(*args); end
|
2013-03-27 17:45:05 -04:00
|
|
|
end
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
class Grungy < Classy
|
|
|
|
# grungy initialize??
|
|
|
|
def initialize(*args); end
|
2013-03-27 17:45:05 -04:00
|
|
|
end
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
@o = Grungy.new
|
2013-03-27 17:45:05 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# instancey initialize!
|
|
|
|
def @o.initialize; end
|
|
|
|
end
|
2011-10-15 04:30:20 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
after do
|
|
|
|
Object.remove_const(:Grungy)
|
|
|
|
Object.remove_const(:Classy)
|
|
|
|
Object.remove_const(:Daddy)
|
|
|
|
end
|
2012-07-25 00:13:32 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "finds super method docs" do
|
|
|
|
output = pry_eval(binding, 'show-doc --super @o.initialize')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(output).to match(/grungy initialize/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-05-03 17:33:38 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "traverses ancestor chain and finds super method docs" do
|
|
|
|
output = pry_eval(binding, 'show-doc -ss @o.initialize')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(output).to match(/classy initialize/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-05-03 17:33:38 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "traverses ancestor chain even higher and finds super method doc" do
|
|
|
|
output = pry_eval(binding, 'show-doc @o.initialize -sss')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(output).to match(/daddy initialize/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-05-17 20:23:01 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "finds super method docs without explicit method argument" do
|
|
|
|
fatty = Grungy.new
|
2013-05-03 17:33:38 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# fatty initialize!
|
|
|
|
def fatty.initialize
|
|
|
|
pry_eval(binding, 'show-doc --super')
|
2013-05-03 17:33:38 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
|
|
|
|
output = fatty.initialize
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(output).to match(/grungy initialize/)
|
2011-10-15 04:30:20 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "finds super method docs without `--super` but with the `super` keyword" do
|
|
|
|
fatty = Grungy.new
|
|
|
|
|
|
|
|
fatty.extend Module.new {
|
|
|
|
def initialize
|
|
|
|
:nibble
|
2012-05-05 03:34:20 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# fatty initialize!
|
|
|
|
def fatty.initialize
|
|
|
|
pry_eval(binding, 'show-doc --super --super')
|
2012-05-05 03:34:20 -04:00
|
|
|
end
|
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
output = fatty.initialize
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(output).to match(/grungy initialize/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
|
|
|
end
|
2012-05-05 03:34:20 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "rdoc highlighting" do
|
|
|
|
it "should syntax highlight code in rdoc" do
|
2015-01-23 04:30:41 -05:00
|
|
|
_c = Class.new{
|
2013-10-24 01:58:26 -04:00
|
|
|
# This can initialize your class:
|
|
|
|
#
|
2015-01-23 04:30:41 -05:00
|
|
|
# a = _c.new :foo
|
2013-10-24 01:58:26 -04:00
|
|
|
#
|
|
|
|
# @param foo
|
|
|
|
def initialize(foo); end
|
|
|
|
}
|
|
|
|
|
|
|
|
begin
|
|
|
|
t = pry_tester(binding)
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.eval("show-doc _c#initialize")).to match(/_c.new :foo/)
|
2013-10-24 01:58:26 -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.
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.eval("show-doc _c#initialize")).not_to match(/_c.new :foo/)
|
2013-10-24 01:58:26 -04:00
|
|
|
ensure
|
|
|
|
Pry.config.color = false
|
2012-05-05 03:34:20 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-05-05 03:34:20 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "should syntax highlight `code` in rdoc" do
|
2015-01-23 04:30:41 -05:00
|
|
|
_c = Class.new{
|
|
|
|
# After initializing your class with `_c.new(:foo)`, go have fun!
|
2013-10-24 01:58:26 -04:00
|
|
|
#
|
|
|
|
# @param foo
|
|
|
|
def initialize(foo); end
|
|
|
|
}
|
|
|
|
|
|
|
|
begin
|
|
|
|
t = pry_tester(binding)
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.eval("show-doc _c#initialize")).to match(/_c.new\(:foo\)/)
|
2013-10-24 01:58:26 -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.
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.eval("show-doc _c#initialize")).not_to match(/_c.new\(:foo\)/)
|
2013-10-24 01:58:26 -04:00
|
|
|
ensure
|
|
|
|
Pry.config.color = false
|
2012-05-05 03:34:20 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
|
2012-05-05 03:34:20 -04:00
|
|
|
end
|
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "should not syntax highlight `` inside code" do
|
2015-01-23 04:30:41 -05:00
|
|
|
_c = Class.new{
|
2013-10-24 01:58:26 -04:00
|
|
|
# Convert aligned output (from many shell commands) into nested arrays:
|
|
|
|
#
|
|
|
|
# a = decolumnize `ls -l $HOME`
|
|
|
|
#
|
|
|
|
# @param output
|
|
|
|
def decolumnize(output); end
|
|
|
|
}
|
|
|
|
|
|
|
|
begin
|
|
|
|
t = pry_tester(binding)
|
|
|
|
Pry.config.color = true
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.eval("show-doc _c#decolumnize")).to match(/ls -l \$HOME/)
|
|
|
|
expect(t.eval("show-doc _c#decolumnize")).not_to match(/`ls -l \$HOME`/)
|
2013-10-24 01:58:26 -04:00
|
|
|
ensure
|
|
|
|
Pry.config.color = false
|
2012-07-20 14:46:53 -04:00
|
|
|
end
|
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-07-20 14:46:53 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "on sourcable objects" do
|
|
|
|
it "should show documentation for object" do
|
|
|
|
# this is a documentation
|
2015-01-23 04:30:41 -05:00
|
|
|
_hello = proc { puts 'hello world!' }
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry(binding, "show-doc _hello")).to match(/this is a documentation/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "on modules" do
|
|
|
|
before do
|
|
|
|
# god this is boring1
|
|
|
|
class ShowSourceTestClass
|
|
|
|
def alpha
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# god this is boring2
|
|
|
|
module ShowSourceTestModule
|
|
|
|
def alpha
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# god this is boring3
|
|
|
|
ShowSourceTestClassWeirdSyntax = Class.new do
|
|
|
|
def beta
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# god this is boring4
|
|
|
|
ShowSourceTestModuleWeirdSyntax = Module.new do
|
|
|
|
def beta
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
after do
|
|
|
|
Object.remove_const :ShowSourceTestClass
|
|
|
|
Object.remove_const :ShowSourceTestClassWeirdSyntax
|
|
|
|
Object.remove_const :ShowSourceTestModule
|
|
|
|
Object.remove_const :ShowSourceTestModuleWeirdSyntax
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "basic functionality, should show docs for top-level module definitions" do
|
|
|
|
it 'should show docs for a class' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval("show-doc ShowSourceTestClass")).to match(
|
2013-10-24 01:58:26 -04:00
|
|
|
/god this is boring1/
|
2015-03-10 16:49:29 -04:00
|
|
|
)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should show docs for a module' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval("show-doc ShowSourceTestModule")).to match(
|
2013-10-24 01:58:26 -04:00
|
|
|
/god this is boring2/
|
2015-03-10 16:49:29 -04:00
|
|
|
)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should show docs for a class when Const = Class.new syntax is used' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval("show-doc ShowSourceTestClassWeirdSyntax")).to match(
|
2013-10-24 01:58:26 -04:00
|
|
|
/god this is boring3/
|
2015-03-10 16:49:29 -04:00
|
|
|
)
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should show docs for a module when Const = Module.new syntax is used' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval("show-doc ShowSourceTestModuleWeirdSyntax")).to match(
|
2013-10-24 01:58:26 -04:00
|
|
|
/god this is boring4/
|
2015-03-10 16:49:29 -04:00
|
|
|
)
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "in REPL" do
|
|
|
|
it 'should find class defined in repl' do
|
|
|
|
t = pry_tester
|
|
|
|
t.eval <<-RUBY
|
|
|
|
# hello tobina
|
|
|
|
class TobinaMyDog
|
|
|
|
def woof
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
RUBY
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.eval('show-doc TobinaMyDog')).to match(/hello tobina/)
|
2013-10-24 01:58:26 -04:00
|
|
|
Object.remove_const :TobinaMyDog
|
|
|
|
end
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should lookup module name with respect to current context' do
|
|
|
|
constant_scope(:AlphaClass, :BetaClass) do
|
|
|
|
# top-level beta
|
|
|
|
class BetaClass
|
|
|
|
def alpha
|
2013-02-07 21:09:56 -05:00
|
|
|
end
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
class AlphaClass
|
|
|
|
# nested beta
|
|
|
|
class BetaClass
|
|
|
|
def beta
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
2013-02-07 21:09:56 -05:00
|
|
|
end
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval(AlphaClass, "show-doc BetaClass")).to match(/nested beta/)
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-10 12:47:15 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should look up nested modules' do
|
|
|
|
constant_scope(:AlphaClass) do
|
|
|
|
class AlphaClass
|
|
|
|
# nested beta
|
|
|
|
class BetaClass
|
2013-03-06 03:22:20 -05:00
|
|
|
def beta
|
2013-02-10 12:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-02-07 21:09:56 -05:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval("show-doc AlphaClass::BetaClass")).to match(
|
2013-10-24 01:58:26 -04:00
|
|
|
/nested beta/
|
2015-03-10 16:49:29 -04:00
|
|
|
)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
|
|
|
end
|
2013-03-14 11:51:05 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "show-doc -a" do
|
|
|
|
it 'should show the docs for all monkeypatches defined in different files' do
|
|
|
|
# local monkeypatch
|
|
|
|
class TestClassForShowSource
|
2015-01-23 04:30:41 -05:00
|
|
|
def epsilon
|
2013-03-14 11:51:05 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-03-14 11:51:05 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
result = pry_eval("show-doc TestClassForShowSource -a")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(result).to match(/used by/)
|
|
|
|
expect(result).to match(/local monkeypatch/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-07 21:09:56 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "messages relating to -a" do
|
|
|
|
it "displays the original definition by default (not a doc of a monkeypatch)" do
|
|
|
|
class TestClassForCandidatesOrder
|
|
|
|
def beta
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-02-07 21:09:56 -05:00
|
|
|
end
|
2012-07-01 11:33:13 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
result = pry_eval("show-doc TestClassForCandidatesOrder")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(result).to match(/Number of monkeypatches: 2/)
|
|
|
|
expect(result).to match(/The first definition/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-07-01 11:33:13 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'indicates all available monkeypatches can be shown with -a ' \
|
|
|
|
'(when -a not used and more than one candidate exists for class)' do
|
|
|
|
# Still reading boring tests, eh?
|
|
|
|
class TestClassForShowSource
|
2015-01-23 04:30:41 -05:00
|
|
|
def delta
|
2012-07-01 11:33:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
result = pry_eval('show-doc TestClassForShowSource')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(result).to match(/available monkeypatches/)
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2012-07-01 11:33:13 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'shouldnt say anything about monkeypatches when only one candidate exists for selected class' do
|
|
|
|
# Do not remove me.
|
|
|
|
class Aarrrrrghh
|
|
|
|
def o;end
|
|
|
|
end
|
|
|
|
|
|
|
|
result = pry_eval('show-doc Aarrrrrghh')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(result).not_to match(/available monkeypatches/)
|
2013-10-24 01:58:26 -04:00
|
|
|
Object.remove_const(:Aarrrrrghh)
|
2012-07-01 11:33:13 -04:00
|
|
|
end
|
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-07-01 11:33:13 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "when no class/module arg is given" do
|
|
|
|
before do
|
|
|
|
module TestHost
|
2013-03-06 03:22:20 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# hello there froggy
|
|
|
|
module M
|
|
|
|
def d; end
|
|
|
|
def e; end
|
2013-01-28 19:12:18 -05:00
|
|
|
end
|
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-01-28 19:12:18 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
after do
|
|
|
|
Object.remove_const(:TestHost)
|
|
|
|
end
|
2013-01-28 19:12:18 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should return doc for current module' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval(TestHost::M, "show-doc")).to match(/hello there froggy/)
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
|
|
|
end
|
2012-07-01 11:33:13 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# FIXME: THis is nto a good spec anyway, because i dont think it
|
|
|
|
# SHOULD skip!
|
|
|
|
describe "should skip over broken modules" do
|
2013-03-06 03:22:20 -05:00
|
|
|
before do
|
2013-10-24 01:58:26 -04:00
|
|
|
module TestHost
|
|
|
|
# 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
|
2012-08-13 23:54:07 -04:00
|
|
|
end
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2012-08-13 23:54:07 -04:00
|
|
|
|
2013-03-06 03:22:20 -05:00
|
|
|
after do
|
2013-10-24 01:58:26 -04:00
|
|
|
Object.remove_const(:TestHost)
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2012-12-27 16:53:51 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should return doc for first valid module' do
|
|
|
|
result = pry_eval("show-doc TestHost::M")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(result).to match(/goodbye/)
|
|
|
|
expect(result).not_to match(/hello/)
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-07 21:09:56 -05:00
|
|
|
|
2013-10-24 01:58:26 -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
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-12-27 16:53:51 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
after do
|
|
|
|
Pry.config.commands = @oldset
|
|
|
|
end
|
2012-12-27 16:53:51 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should display help for a specific command' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval('show-doc ls')).to match(/Usage: ls/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-12-27 16:53:51 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should display help for a regex command with a "listing"' do
|
2015-01-23 04:30:41 -05:00
|
|
|
@set.command(/bar(.*)/, "Test listing", :listing => "foo") do; end
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval('show-doc foo')).to match(/Test listing/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-12-27 16:53:51 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
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
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval('show-doc command with spaces')).to match(/description of a command with spaces/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-03-06 03:22:20 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "class commands" do
|
|
|
|
before do
|
|
|
|
# pretty pink pincers
|
|
|
|
class LobsterLady < Pry::ClassCommand
|
|
|
|
match "lobster-lady"
|
|
|
|
description "nada."
|
|
|
|
def process
|
|
|
|
"lobster"
|
|
|
|
end
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
|
|
|
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.commands.add_command(LobsterLady)
|
2012-12-27 16:53:51 -05:00
|
|
|
end
|
2012-12-22 16:54:17 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
after do
|
|
|
|
Object.remove_const(:LobsterLady)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display "help" when looking up by command name' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval('show-doc lobster-lady')).to match(/nada/)
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.commands.delete("lobster-lady")
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display actual preceding comment for a class command, when class is used (rather than command name) when looking up' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval('show-doc LobsterLady')).to match(/pretty pink pincers/)
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.commands.delete("lobster-lady")
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "should set _file_ and _dir_" do
|
|
|
|
it 'should set _file_ and _dir_ to file containing method source' do
|
|
|
|
t = pry_tester
|
|
|
|
t.process_command "show-doc TestClassForShowSource#alpha"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.pry.last_file).to match(/show_source_doc_examples/)
|
|
|
|
expect(t.pry.last_dir).to match(/fixtures/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
unless Pry::Helpers::BaseHelpers.rbx?
|
|
|
|
describe "can't find class docs" do
|
|
|
|
describe "for classes" do
|
|
|
|
before do
|
|
|
|
module Jesus
|
|
|
|
class Brian; end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# doink-doc
|
|
|
|
class Jingle
|
|
|
|
def a; :doink; end
|
2013-02-07 21:09:56 -05:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
class Jangle < Jingle; end
|
|
|
|
class Bangle < Jangle; end
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
after do
|
|
|
|
Object.remove_const(:Jesus)
|
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'shows superclass doc' do
|
|
|
|
t = pry_tester
|
|
|
|
t.process_command "show-doc Jesus::Jangle"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.last_output).to match(/doink-doc/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'errors when class has no superclass to show' do
|
|
|
|
t = pry_tester
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { t.process_command "show-doc Jesus::Brian" }.to raise_error(Pry::CommandError, /Couldn't locate/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'shows warning when reverting to superclass docs' do
|
|
|
|
t = pry_tester
|
|
|
|
t.process_command "show-doc Jesus::Jangle"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.last_output).to match(/Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'shows nth level superclass docs (when no intermediary superclasses have code either)' do
|
|
|
|
t = pry_tester
|
|
|
|
t.process_command "show-doc Jesus::Bangle"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.last_output).to match(/doink-doc/)
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'shows correct warning when reverting to nth level superclass' do
|
|
|
|
t = pry_tester
|
|
|
|
t.process_command "show-doc Jesus::Bangle"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.last_output).to match(/Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "for modules" do
|
|
|
|
before do
|
|
|
|
module Jesus
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
# alpha-doc
|
|
|
|
module Alpha
|
|
|
|
def alpha; :alpha; end
|
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
module Zeta; end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
module Beta
|
|
|
|
include Alpha
|
2013-02-07 21:09:56 -05:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
module Gamma
|
|
|
|
include Beta
|
|
|
|
end
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
after do
|
|
|
|
Object.remove_const(:Jesus)
|
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'shows included module doc' do
|
|
|
|
t = pry_tester
|
|
|
|
t.process_command "show-doc Jesus::Beta"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.last_output).to match(/alpha-doc/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'shows warning when reverting to included module doc' do
|
|
|
|
t = pry_tester
|
|
|
|
t.process_command "show-doc Jesus::Beta"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.last_output).to match(/Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-02-07 09:48:43 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'errors when module has no included module to show' do
|
|
|
|
t = pry_tester
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { t.process_command "show-source Jesus::Zeta" }.to raise_error(Pry::CommandError, /Couldn't locate/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2013-03-06 03:22:20 -05:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'shows nth level included module doc (when no intermediary modules have code either)' do
|
|
|
|
t = pry_tester
|
|
|
|
t.process_command "show-doc Jesus::Gamma"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.last_output).to match(/alpha-doc/)
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows correct warning when reverting to nth level included module' do
|
|
|
|
t = pry_tester
|
|
|
|
t.process_command "show-source Jesus::Gamma"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.last_output).to match(/Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/)
|
2013-02-07 09:48:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-04-18 01:19:25 -04:00
|
|
|
end
|
2013-03-06 03:22:20 -05:00
|
|
|
end
|