Skip to content

Commit

Permalink
Misspelled words are now printed to $stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Apr 5, 2012
1 parent 335d50d commit 403c948
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rdoc/discover.rb
@@ -1,2 +1,2 @@
require 'rdoc/spellcheck'
require 'rdoc/generator/spellcheck'

27 changes: 27 additions & 0 deletions lib/rdoc/generator/spellcheck.rb
Expand Up @@ -7,6 +7,12 @@

require 'raspell'

##
# A spell checking generator for RDoc.
#
# This generator creates a report of misspelled words. You can use it to find
# when you acidentally make a typo. For example, this line contains one.

class RDoc::Generator::Spellcheck

RDoc::RDoc.add_generator self
Expand Down Expand Up @@ -49,6 +55,27 @@ def self.setup_options options
end
end

def initialize options # :not-new:
@options = options

@spell = Aspell.new @options.spell_language
end

##
# Creates the spelling report

def generate files
RDoc::TopLevel.all_classes_and_modules.each do |mod|
mod.comment_location.each do |comment, location|
comment.text.scan(/[a-z_]+/i) do |word|
next if @spell.check word

puts word
end
end
end
end

end

class RDoc::Options
Expand Down
21 changes: 20 additions & 1 deletion test/test_rdoc_generator_spellcheck.rb
Expand Up @@ -9,7 +9,11 @@ class TestRDocGeneratorSpellcheck < RDoc::TestCase
def setup
super

@S = RDoc::Generator::Spellcheck
@SC = RDoc::Generator::Spellcheck
@options = RDoc::Options.new
@options.spell_language = 'en_US'

@sc = @SC.new @options
end

def test_class_setup_options_default
Expand All @@ -35,5 +39,20 @@ def test_class_setup_options_spell_language
assert_equal 'en_GB', options.spell_language
end

def test_generate
tl = RDoc::TopLevel.new 'file.rb'
klass = tl.add_class RDoc::NormalClass, 'Object'

comment = RDoc::Comment.new 'Hello, this class has real gud spelling!', tl
klass.add_comment comment, tl

out, err = capture_io do
@sc.generate [tl]
end

assert_empty err
assert_equal "gud\n", out
end

end

0 comments on commit 403c948

Please sign in to comment.