Permalink
Browse files

Refactored report loop for a class comment to misspellings_for

  • Loading branch information...
1 parent 53636c7 commit f9d937f83aa89124f619f68ee0fc5acbb5406be5 @drbrain drbrain committed Apr 5, 2012
Showing with 36 additions and 13 deletions.
  1. +27 −13 lib/rdoc/generator/spellcheck.rb
  2. +9 −0 test/test_rdoc_generator_spellcheck.rb
@@ -58,7 +58,8 @@ def self.setup_options options
def initialize options # :not-new:
@options = options
- @spell = Aspell.new @options.spell_language
+ @misspellings = 0
+ @spell = Aspell.new @options.spell_language
end
##
@@ -81,25 +82,38 @@ def find_misspelled comment
# Creates the spelling report
def generate files
- misspellings = 0
+ report = []
RDoc::TopLevel.all_classes_and_modules.each do |mod|
mod.comment_location.each do |comment, location|
- misspelled = find_misspelled comment
+ report.concat misspellings_for(mod.definition, comment, location)
+ end
+ end
- next if misspelled.empty?
+ if @misspellings.zero? then
+ puts 'No misspellings found'
+ else
+ puts report.join "\n"
+ end
- misspellings += misspelled.length
+ end
- puts "#{mod.definition} in #{location.full_name}:"
- puts
- misspelled.each do |word, offset|
- puts suggestion_text(comment.text, word, offset)
- end
- end
- end
+ def misspellings_for name, comment, location
+ out = []
+
+ misspelled = find_misspelled comment
+
+ return out if misspelled.empty?
+
+ @misspellings += misspelled.length
+
+ out << "#{name} in #{location.full_name}:"
+ out << nil
+ out.concat misspelled.map { |word, offset|
+ suggestion_text comment.text, word, offset
+ }
- puts 'No misspellings found' if misspellings.zero?
+ out
end
def suggestion_text text, word, offset
@@ -84,6 +84,15 @@ def test_generate_correct
assert_equal "No misspellings found\n", out
end
+ def test_misspellings_for
+ out = @sc.misspellings_for 'class Object', comment(@text), @top_level
+
+ out = out.join "\n"
+
+ assert_match %r%^class Object in file\.rb:%, out
+ assert_match %r%^"gud"%, out
+ end
+
def test_suggestion_text
out = @sc.suggestion_text @text, 'gud', 28

0 comments on commit f9d937f

Please sign in to comment.