diff --git a/lib/pry/commands/show_info.rb b/lib/pry/commands/show_info.rb index 04817d40..3e3da608 100644 --- a/lib/pry/commands/show_info.rb +++ b/lib/pry/commands/show_info.rb @@ -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) diff --git a/spec/commands/show_doc_spec.rb b/spec/commands/show_doc_spec.rb index b69eee43..19bbca1f 100644 --- a/spec/commands/show_doc_spec.rb +++ b/spec/commands/show_doc_spec.rb @@ -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 diff --git a/spec/commands/show_source_spec.rb b/spec/commands/show_source_spec.rb index 9dc87453..a5b9a96d 100644 --- a/spec/commands/show_source_spec.rb +++ b/spec/commands/show_source_spec.rb @@ -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