2012-04-18 17:19:25 +12:00
|
|
|
require 'helper'
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
if !mri18_and_no_real_source_location?
|
|
|
|
describe "show-source" do
|
2012-06-11 16:36:16 +03:00
|
|
|
before do
|
|
|
|
@str_output = StringIO.new
|
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should output a method\'s source' do
|
2012-06-11 16:36:16 +03:00
|
|
|
redirect_pry_io(InputTester.new("show-source sample_method", "exit-all"), @str_output) do
|
2012-04-18 18:18:33 +12:00
|
|
|
pry
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-06-11 16:36:16 +03:00
|
|
|
@str_output.string.should =~ /def sample/
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should output help' do
|
|
|
|
mock_pry('show-source -h').should =~ /Usage: show-source/
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should output a method\'s source with line numbers' do
|
2012-06-11 16:36:16 +03:00
|
|
|
redirect_pry_io(InputTester.new("show-source -l sample_method", "exit-all"), @str_output) do
|
2012-04-18 18:18:33 +12:00
|
|
|
pry
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-06-11 16:36:16 +03:00
|
|
|
@str_output.string.should =~ /\d+: def sample/
|
2012-04-18 18:18:33 +12:00
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should output a method\'s source with line numbers starting at 1' do
|
2012-06-11 16:36:16 +03:00
|
|
|
redirect_pry_io(InputTester.new("show-source -b sample_method", "exit-all"), @str_output) do
|
2012-04-18 18:18:33 +12:00
|
|
|
pry
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-06-11 16:36:16 +03:00
|
|
|
@str_output.string.should =~ /1: def sample/
|
2012-04-18 18:18:33 +12:00
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should output a method\'s source if inside method without needing to use method name' do
|
|
|
|
$str_output = StringIO.new
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
o = Object.new
|
|
|
|
def o.sample
|
|
|
|
redirect_pry_io(InputTester.new("show-source", "exit-all"), $str_output) do
|
|
|
|
binding.pry
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
2012-04-18 18:18:33 +12:00
|
|
|
o.sample
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
$str_output.string.should =~ /def o.sample/
|
|
|
|
$str_output = nil
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do
|
|
|
|
$str_output = StringIO.new
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
o = Object.new
|
|
|
|
def o.sample
|
|
|
|
redirect_pry_io(InputTester.new("show-source -l", "exit-all"), $str_output) do
|
|
|
|
binding.pry
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
2012-04-18 18:18:33 +12:00
|
|
|
o.sample
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
$str_output.string.should =~ /\d+: def o.sample/
|
|
|
|
$str_output = nil
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should find methods even if there are spaces in the arguments" do
|
|
|
|
o = Object.new
|
|
|
|
def o.foo(*bars);
|
|
|
|
"Mr flibble"
|
|
|
|
self;
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-06-11 16:36:16 +03:00
|
|
|
redirect_pry_io(InputTester.new("show-source o.foo('bar', 'baz bam').foo", "exit-all"), @str_output) do
|
2012-04-18 18:18:33 +12:00
|
|
|
binding.pry
|
|
|
|
end
|
2012-06-11 16:36:16 +03:00
|
|
|
|
|
|
|
@str_output.string.should =~ /Mr flibble/
|
2012-04-18 18:18:33 +12:00
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should find methods even if the object has an overridden method method" do
|
|
|
|
c = Class.new{
|
|
|
|
def method;
|
|
|
|
98
|
|
|
|
end
|
|
|
|
}
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
mock_pry(binding, "show-source c.new.method").should =~ /98/
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should find instance_methods even if the class has an override instance_method method" do
|
|
|
|
c = Class.new{
|
|
|
|
def method;
|
|
|
|
98
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
def self.instance_method; 789; end
|
|
|
|
}
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
mock_pry(binding, "show-source c#method").should =~ /98/
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should find instance methods with -M" do
|
|
|
|
c = Class.new{ def moo; "ve over!"; end }
|
|
|
|
mock_pry(binding, "cd c","show-source -M moo").should =~ /ve over/
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should not find instance methods with -m" do
|
|
|
|
c = Class.new{ def moo; "ve over!"; end }
|
|
|
|
mock_pry(binding, "cd c", "show-source -m moo").should =~ /could not be found/
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should find normal methods with -m" do
|
|
|
|
c = Class.new{ def self.moo; "ve over!"; end }
|
|
|
|
mock_pry(binding, "cd c", "show-source -m moo").should =~ /ve over/
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should not find normal methods with -M" do
|
|
|
|
c = Class.new{ def self.moo; "ve over!"; end }
|
|
|
|
mock_pry(binding, "cd c", "show-source -M moo").should =~ /could not be found/
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should find normal methods with no -M or -m" do
|
|
|
|
c = Class.new{ def self.moo; "ve over!"; end }
|
|
|
|
mock_pry(binding, "cd c", "show-source moo").should =~ /ve over/
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should find instance methods with no -M or -m" do
|
|
|
|
c = Class.new{ def moo; "ve over!"; end }
|
|
|
|
mock_pry(binding, "cd c", "show-source moo").should =~ /ve over/
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should find super methods" do
|
|
|
|
class Foo
|
|
|
|
def foo(*bars)
|
|
|
|
:super_wibble
|
|
|
|
end
|
|
|
|
end
|
|
|
|
o = Foo.new
|
|
|
|
Object.remove_const(:Foo)
|
|
|
|
def o.foo(*bars)
|
|
|
|
:wibble
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
mock_pry(binding, "show-source --super o.foo").should =~ /:super_wibble/
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it "should not raise an exception when a non-extant super method is requested" do
|
|
|
|
o = Object.new
|
|
|
|
def o.foo(*bars); end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
mock_pry(binding, "show-source --super o.foo").should =~ /'self.foo' has no super method/
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
# dynamically defined method source retrieval is only supported in
|
|
|
|
# 1.9 - where Method#source_location is native
|
|
|
|
if RUBY_VERSION =~ /1.9/
|
|
|
|
it 'should output a method\'s source for a method defined inside pry' do
|
2012-06-11 16:36:16 +03:00
|
|
|
redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-source dyna_method"), @str_output) do
|
2012-04-18 18:18:33 +12:00
|
|
|
TOPLEVEL_BINDING.pry
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
2012-04-18 18:18:33 +12:00
|
|
|
|
2012-06-11 16:36:16 +03:00
|
|
|
@str_output.string.should =~ /def dyna_method/
|
2012-04-18 18:18:33 +12:00
|
|
|
Object.remove_method :dyna_method
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do
|
2012-06-11 16:36:16 +03:00
|
|
|
redirect_pry_io(InputTester.new("bad code", "123", "bad code 2", "1 + 2", "def dyna_method", ":testing", "end", "show-source dyna_method"), @str_output) do
|
2012-04-18 18:18:33 +12:00
|
|
|
TOPLEVEL_BINDING.pry
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
2012-04-18 18:18:33 +12:00
|
|
|
|
2012-06-11 16:36:16 +03:00
|
|
|
@str_output.string.should =~ /def dyna_method/
|
2012-04-18 18:18:33 +12:00
|
|
|
Object.remove_method :dyna_method
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should output an instance method\'s source for a method defined inside pry' do
|
|
|
|
Object.remove_const :A if defined?(A)
|
2012-06-11 16:36:16 +03:00
|
|
|
redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-source A#yo"), @str_output) do
|
2012-04-18 18:18:33 +12:00
|
|
|
TOPLEVEL_BINDING.pry
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
2012-04-18 18:18:33 +12:00
|
|
|
|
2012-06-11 16:36:16 +03:00
|
|
|
@str_output.string.should =~ /def yo/
|
2012-04-18 18:18:33 +12:00
|
|
|
Object.remove_const :A
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should output an instance method\'s source for a method defined inside pry using define_method' do
|
|
|
|
Object.remove_const :A if defined?(A)
|
2012-06-11 16:36:16 +03:00
|
|
|
redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "show-source A#yup"), @str_output) do
|
2012-04-18 18:18:33 +12:00
|
|
|
TOPLEVEL_BINDING.pry
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
2012-04-18 18:18:33 +12:00
|
|
|
|
2012-06-11 16:36:16 +03:00
|
|
|
@str_output.string.should =~ /define_method\(:yup\)/
|
2012-04-18 18:18:33 +12:00
|
|
|
Object.remove_const :A
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
describe "on modules" do
|
|
|
|
before do
|
|
|
|
class ShowSourceTestClass
|
|
|
|
def alpha
|
|
|
|
end
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
module ShowSourceTestModule
|
|
|
|
def alpha
|
|
|
|
end
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
ShowSourceTestClassWeirdSyntax = Class.new do
|
|
|
|
def beta
|
|
|
|
end
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
ShowSourceTestModuleWeirdSyntax = Module.new do
|
|
|
|
def beta
|
|
|
|
end
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
after do
|
|
|
|
Object.remove_const :ShowSourceTestClass
|
|
|
|
Object.remove_const :ShowSourceTestClassWeirdSyntax
|
|
|
|
Object.remove_const :ShowSourceTestModule
|
|
|
|
Object.remove_const :ShowSourceTestModuleWeirdSyntax
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
describe "basic functionality, should find top-level module definitions" do
|
|
|
|
it 'should show source for a class' do
|
|
|
|
mock_pry("show-source ShowSourceTestClass").should =~ /class ShowSourceTest.*?def alpha/m
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should show source for a module' do
|
|
|
|
mock_pry("show-source ShowSourceTestModule").should =~ /module ShowSourceTestModule/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should show source for a class when Const = Class.new syntax is used' do
|
|
|
|
mock_pry("show-source ShowSourceTestClassWeirdSyntax").should =~ /ShowSourceTestClassWeirdSyntax = Class.new/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should show source for a module when Const = Module.new syntax is used' do
|
|
|
|
mock_pry("show-source ShowSourceTestModuleWeirdSyntax").should =~ /ShowSourceTestModuleWeirdSyntax = Module.new/
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
if !Pry::Helpers::BaseHelpers.mri_18?
|
|
|
|
describe "in REPL" do
|
|
|
|
it 'should find class defined in repl' do
|
|
|
|
mock_pry("class TobinaMyDog", "def woof", "end", "end", "show-source TobinaMyDog").should =~ /class TobinaMyDog/
|
|
|
|
Object.remove_const :TobinaMyDog
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
end
|
2012-04-18 18:18:33 +12:00
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should lookup module name with respect to current context' do
|
|
|
|
constant_scope(:AlphaClass, :BetaClass) do
|
2012-04-18 17:19:25 +12:00
|
|
|
class BetaClass
|
2012-04-18 18:18:33 +12:00
|
|
|
def alpha
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
class AlphaClass
|
|
|
|
class BetaClass
|
|
|
|
def beta
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_pry_io(InputTester.new("show-source BetaClass", "exit-all"), out=StringIO.new) do
|
|
|
|
AlphaClass.pry
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
out.string.should =~ /def beta/
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
it 'should lookup nested modules' do
|
|
|
|
constant_scope(:AlphaClass) do
|
|
|
|
class AlphaClass
|
|
|
|
class BetaClass
|
|
|
|
def beta
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
mock_pry("show-source AlphaClass::BetaClass").should =~ /class BetaClass/
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-06-04 05:00:11 +12:00
|
|
|
# note that pry assumes a class is only monkey-patched at most
|
|
|
|
# ONCE per file, so will not find multiple monkeypatches in the
|
|
|
|
# SAME file.
|
2012-04-18 18:18:33 +12:00
|
|
|
describe "show-source -a" do
|
|
|
|
it 'should show the source for all monkeypatches defined in different files' do
|
|
|
|
class TestClassForShowSource
|
|
|
|
def beta
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
|
2012-04-18 18:18:33 +12:00
|
|
|
result = mock_pry("show-source TestClassForShowSource -a")
|
|
|
|
result.should =~ /def alpha/
|
|
|
|
result.should =~ /def beta/
|
|
|
|
end
|
2012-06-04 05:00:11 +12:00
|
|
|
|
|
|
|
it 'should show the source for a class_eval-based monkeypatch' do
|
|
|
|
TestClassForShowSourceClassEval.class_eval do
|
|
|
|
def class_eval_method
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
result = mock_pry("show-source TestClassForShowSourceClassEval -a")
|
|
|
|
result.should =~ /def class_eval_method/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should show the source for an instance_eval-based monkeypatch' do
|
|
|
|
TestClassForShowSourceInstanceEval.instance_eval do
|
|
|
|
def instance_eval_method
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
result = mock_pry("show-source TestClassForShowSourceInstanceEval -a")
|
|
|
|
result.should =~ /def instance_eval_method/
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
2012-06-28 15:32:45 +12:00
|
|
|
|
|
|
|
describe "when show-source is invoked without a method or class argument" do
|
|
|
|
before do
|
2012-06-28 15:43:40 +12:00
|
|
|
module TestHost
|
|
|
|
class M
|
2012-06-28 15:32:45 +12:00
|
|
|
def alpha; end
|
|
|
|
def beta; end
|
|
|
|
end
|
|
|
|
|
|
|
|
module C
|
|
|
|
end
|
|
|
|
|
|
|
|
module D
|
|
|
|
def self.invoked_in_method
|
|
|
|
redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
|
|
|
|
Pry.start(binding)
|
|
|
|
end
|
|
|
|
out.string
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2012-06-28 15:43:40 +12:00
|
|
|
Object.remove_const(:TestHost)
|
2012-06-28 15:32:45 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "inside a module" do
|
|
|
|
it 'should display module source by default' do
|
|
|
|
redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
|
2012-06-28 15:43:40 +12:00
|
|
|
Pry.start(TestHost::M)
|
2012-06-28 15:32:45 +12:00
|
|
|
end
|
|
|
|
|
2012-06-28 15:43:40 +12:00
|
|
|
out.string.should =~ /class M/
|
2012-06-28 15:32:45 +12:00
|
|
|
out.string.should =~ /def alpha/
|
|
|
|
out.string.should =~ /def beta/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be unable to find module source if no methods defined' do
|
|
|
|
redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
|
2012-06-28 15:43:40 +12:00
|
|
|
Pry.start(TestHost::C)
|
2012-06-28 15:32:45 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
out.string.should.should =~ /Cannot find a definition for/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display method code (rather than class) if Pry started inside method binding' do
|
2012-06-28 15:43:40 +12:00
|
|
|
string = TestHost::D.invoked_in_method
|
2012-06-28 15:32:45 +12:00
|
|
|
string.should =~ /invoked_in_method/
|
|
|
|
string.should.not =~ /module D/
|
|
|
|
end
|
|
|
|
|
2012-06-28 15:43:40 +12:00
|
|
|
it 'should display class source when inside instance' do
|
|
|
|
redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
|
|
|
|
Pry.start(TestHost::M.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
out.string.should =~ /class M/
|
|
|
|
out.string.should =~ /def alpha/
|
|
|
|
out.string.should =~ /def beta/
|
|
|
|
end
|
|
|
|
|
2012-06-28 15:32:45 +12:00
|
|
|
it 'should allow options to be passed' do
|
|
|
|
redirect_pry_io(InputTester.new("show-source -b", "exit-all"), out = StringIO.new) do
|
2012-06-28 15:43:40 +12:00
|
|
|
Pry.start(TestHost::M)
|
2012-06-28 15:32:45 +12:00
|
|
|
end
|
|
|
|
|
2012-06-28 15:43:40 +12:00
|
|
|
out.string.should =~ /\d:\s*class M/
|
2012-06-28 15:32:45 +12:00
|
|
|
out.string.should =~ /\d:\s*def alpha/
|
|
|
|
out.string.should =~ /\d:\s*def beta/
|
|
|
|
end
|
2012-07-02 03:33:13 +12:00
|
|
|
|
|
|
|
describe "should skip over broken modules" do
|
|
|
|
before do
|
|
|
|
module Host
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
module M
|
|
|
|
def d; end
|
|
|
|
def e; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Object.remove_const(:Host)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return source for first valid module' do
|
|
|
|
redirect_pry_io(InputTester.new("show-source Host::M"), out = StringIO.new) do
|
|
|
|
Pry.start
|
|
|
|
end
|
|
|
|
|
|
|
|
out.string.should =~ /def d; end/
|
|
|
|
out.string.should.not =~ /def a; end/
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-06-28 15:32:45 +12:00
|
|
|
end
|
|
|
|
end
|
2012-04-18 17:19:25 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|