From 7c8f9be176b3c11f871abb25bed38d3412b5b6ab Mon Sep 17 00:00:00 2001 From: John Mair Date: Sun, 10 Mar 2013 00:19:10 +0100 Subject: [PATCH] Show error when no docs found --- lib/pry/commands/show_doc.rb | 1 + lib/pry/commands/show_source.rb | 2 -- spec/commands/show_doc_spec.rb | 7 +++++++ spec/fixtures/show_source_doc_examples.rb | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/pry/commands/show_doc.rb b/lib/pry/commands/show_doc.rb index 9d55ffd7..86f74624 100644 --- a/lib/pry/commands/show_doc.rb +++ b/lib/pry/commands/show_doc.rb @@ -35,6 +35,7 @@ class Pry # command '--help' shouldn't use markup highlighting docs else + raise CommandError, "No docs found for: #{obj_name}" if docs.empty? process_comment_markup(docs) end end diff --git a/lib/pry/commands/show_source.rb b/lib/pry/commands/show_source.rb index e5477658..73356d2e 100644 --- a/lib/pry/commands/show_source.rb +++ b/lib/pry/commands/show_source.rb @@ -25,8 +25,6 @@ class Pry # The source for code_object prepared for display. def content_for(code_object) - cannot_locate_source_error if !code_object.source - Code.new(code_object.source, start_line_for(code_object)). with_line_numbers(use_line_numbers?).to_s end diff --git a/spec/commands/show_doc_spec.rb b/spec/commands/show_doc_spec.rb index d530b70f..b69eee43 100644 --- a/spec/commands/show_doc_spec.rb +++ b/spec/commands/show_doc_spec.rb @@ -10,12 +10,19 @@ if !PryTestHelpers.mri18_and_no_real_source_location? def @o.sample_method :sample end + + def @o.no_docs;end + end it 'should output a method\'s documentation' do pry_eval(binding, "show-doc @o.sample_method").should =~ /sample doc/ end + it 'should raise exception when cannot find docs' do + lambda { pry_eval(binding, "show-doc @o.no_docs") }.should.raise(Pry::CommandError) + end + it 'should output a method\'s documentation with line numbers' do pry_eval(binding, "show-doc @o.sample_method -l").should =~ /\d: sample doc/ end diff --git a/spec/fixtures/show_source_doc_examples.rb b/spec/fixtures/show_source_doc_examples.rb index 53804baa..6d8cddfc 100644 --- a/spec/fixtures/show_source_doc_examples.rb +++ b/spec/fixtures/show_source_doc_examples.rb @@ -1,5 +1,6 @@ # used by test_show_source.rb and test_documentation.rb class TestClassForShowSource + #doc def alpha end end