Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

show-source: Indicate all monkeypatches can be shown with -a

Fixes #849
  • Loading branch information...
commit 342648f61f6611de32d8e789f2794603a4e044a4 1 parent db15bdd
@banister banister authored kyrylo committed
View
6 lib/pry/commands/show_info.rb
@@ -126,6 +126,12 @@ def module_header(code_object, line_num)
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)
View
22 spec/commands/show_doc_spec.rb
@@ -261,6 +261,28 @@ def beta
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
View
22 spec/commands/show_source_spec.rb
@@ -453,6 +453,28 @@ def instance_eval_method
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
Please sign in to comment.
Something went wrong with that request. Please try again.