Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Misspelled words are now printed to $stdout

  • Loading branch information...
commit 403c948bfecd5597fce3bcf62902e1ef5206fd3d 1 parent 335d50d
@drbrain drbrain authored
View
2  lib/rdoc/discover.rb
@@ -1,2 +1,2 @@
-require 'rdoc/spellcheck'
+require 'rdoc/generator/spellcheck'
View
27 lib/rdoc/generator/spellcheck.rb
@@ -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
@@ -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
View
21 test/test_rdoc_generator_spellcheck.rb
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.