mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
show-source: Indicate all monkeypatches can be shown with -a
Fixes #849
This commit is contained in:
parent
db15bddb1e
commit
342648f61f
3 changed files with 50 additions and 0 deletions
|
@ -126,6 +126,12 @@ class Pry
|
|||
h << "@ line #{line_num}:\n"
|
||||
h << text.bold(code_object.module? ? "Module" : "Class")
|
||||
h << " #{text.bold('name:')} #{code_object.nonblank_name}"
|
||||
|
||||
if code_object.number_of_candidates > 1
|
||||
h << (text.bold("\nNumber of monkeypatches: ") + code_object.number_of_candidates.to_s)
|
||||
h << ". Use the `-a` option to display all available monkeypatches"
|
||||
end
|
||||
h
|
||||
end
|
||||
|
||||
def method_sections(code_object)
|
||||
|
|
|
@ -261,6 +261,28 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
|
|||
result.should =~ /used by/
|
||||
result.should =~ /local monkeypatch/
|
||||
end
|
||||
|
||||
describe "messages relating to -a" do
|
||||
it 'indicates all available monkeypatches can be shown with -a when (when -a not used and more than one candidate exists for class)' do
|
||||
class TestClassForShowSource
|
||||
def beta
|
||||
end
|
||||
end
|
||||
|
||||
result = pry_eval('show-doc TestClassForShowSource')
|
||||
result.should =~ /available monkeypatches/
|
||||
end
|
||||
|
||||
it 'shouldnt say anything about monkeypatches when only one candidate exists for selected class' do
|
||||
class Aarrrrrghh
|
||||
def o;end
|
||||
end
|
||||
|
||||
result = pry_eval('show-doc Aarrrrrghh')
|
||||
result.should.not =~ /available monkeypatches/
|
||||
Object.remove_const(:Aarrrrrghh)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when no class/module arg is given" do
|
||||
|
|
|
@ -453,6 +453,28 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
|
|||
result = pry_eval('show-source TestClassForShowSourceInstanceEval -a')
|
||||
result.should =~ /def instance_eval_method/
|
||||
end
|
||||
|
||||
describe "messages relating to -a" do
|
||||
it 'indicates all available monkeypatches can be shown with -a when (when -a not used and more than one candidate exists for class)' do
|
||||
class TestClassForShowSource
|
||||
def beta
|
||||
end
|
||||
end
|
||||
|
||||
result = pry_eval('show-source TestClassForShowSource')
|
||||
result.should =~ /available monkeypatches/
|
||||
end
|
||||
|
||||
it 'shouldnt say anything about monkeypatches when only one candidate exists for selected class' do
|
||||
class Aarrrrrghh
|
||||
def o;end
|
||||
end
|
||||
|
||||
result = pry_eval('show-source Aarrrrrghh')
|
||||
result.should.not =~ /available monkeypatches/
|
||||
Object.remove_const(:Aarrrrrghh)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when show-source is invoked without a method or class argument" do
|
||||
|
|
Loading…
Reference in a new issue