[前][次][番号順一覧][スレッド一覧]

ruby-changes:26322

From: drbrain <ko1@a...>
Date: Fri, 14 Dec 2012 14:17:06 +0900 (JST)
Subject: [ruby-changes:26322] drbrain:r38373 (trunk): * lib/rdoc/rubygems_hook.rb: Fixed generation of documentation.

drbrain	2012-12-14 14:16:56 +0900 (Fri, 14 Dec 2012)

  New Revision: 38373

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38373

  Log:
    * lib/rdoc/rubygems_hook.rb:  Fixed generation of documentation.
      Disabled rdoc generation by default to match RubyGems defaults.
      Reduced diff with RubyGems::RDoc.
    * test/rdoc/test_rdoc_rubygems_hook.rb:  Tests for the above.
    * test/rubygems/test_gem_rdoc.rb:  ditto.
    
    * lib/rdoc/store.rb:  Removed useless variable assignment

  Modified files:
    trunk/ChangeLog
    trunk/lib/rdoc/rubygems_hook.rb
    trunk/lib/rdoc/store.rb
    trunk/test/rdoc/test_rdoc_rubygems_hook.rb
    trunk/test/rubygems/test_gem_rdoc.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38372)
+++ ChangeLog	(revision 38373)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Dec 14 14:16:42 2012  Eric Hodel  <drbrain@s...>
+
+	* lib/rdoc/rubygems_hook.rb:  Fixed generation of documentation.
+	  Disabled rdoc generation by default to match RubyGems defaults.
+	  Reduced diff with RubyGems::RDoc.
+	* test/rdoc/test_rdoc_rubygems_hook.rb:  Tests for the above.
+	* test/rubygems/test_gem_rdoc.rb:  ditto.
+
+	* lib/rdoc/store.rb:  Removed useless variable assignment
+
 Fri Dec 14 13:58:40 2012  Eric Hodel  <drbrain@s...>
 
 	* lib/rubygems/commands/rdoc_command.rb:  When overwriting
Index: lib/rdoc/store.rb
===================================================================
--- lib/rdoc/store.rb	(revision 38372)
+++ lib/rdoc/store.rb	(revision 38373)
@@ -596,7 +596,7 @@ class RDoc::Store https://github.com/ruby/ruby/blob/trunk/lib/rdoc/store.rb#L596
   def load_class_data klass_name
     file = class_file klass_name
 
-    obj = open file, 'rb' do |io|
+    open file, 'rb' do |io|
       Marshal.load io.read
     end
   rescue Errno::ENOENT => e
Index: lib/rdoc/rubygems_hook.rb
===================================================================
--- lib/rdoc/rubygems_hook.rb	(revision 38372)
+++ lib/rdoc/rubygems_hook.rb	(revision 38373)
@@ -68,10 +68,12 @@ class RDoc::RubygemsHook https://github.com/ruby/ruby/blob/trunk/lib/rdoc/rubygems_hook.rb#L68
 
   ##
   # Creates a new documentation generator for +spec+.  RDoc and ri data
-  # generation can be disabled through +generate_rdoc+ and +generate_ri+
-  # respectively.
+  # generation can be enabled or disabled through +generate_rdoc+ and
+  # +generate_ri+ respectively.
+  #
+  # Only +generate_ri+ is enabled by default.
 
-  def initialize spec, generate_rdoc = true, generate_ri = true
+  def initialize spec, generate_rdoc = false, generate_ri = true
     @doc_dir   = spec.doc_dir
     @force     = false
     @rdoc      = nil
@@ -139,13 +141,11 @@ class RDoc::RubygemsHook https://github.com/ruby/ruby/blob/trunk/lib/rdoc/rubygems_hook.rb#L141
 
     setup
 
-    options = ::RDoc::Options.new
-    options.default_title = "#{@spec.full_name} Documentation"
-    options.files = []
-    options.files.concat @spec.require_paths
-    options.files.concat @spec.extra_rdoc_files
+    options = nil
 
     args = @spec.rdoc_options
+    args.concat @spec.require_paths
+    args.concat @spec.extra_rdoc_files
 
     case config_args = Gem.configuration[:rdoc]
     when String then
@@ -155,7 +155,13 @@ class RDoc::RubygemsHook https://github.com/ruby/ruby/blob/trunk/lib/rdoc/rubygems_hook.rb#L155
     end
 
     delete_legacy_args args
-    options.parse args
+
+    Dir.chdir @spec.full_gem_path do
+      options = ::RDoc::Options.new
+      options.default_title = "#{@spec.full_name} Documentation"
+      options.parse args
+    end
+
     options.quiet = !Gem.configuration.really_verbose
 
     @rdoc = new_rdoc
@@ -167,7 +173,7 @@ class RDoc::RubygemsHook https://github.com/ruby/ruby/blob/trunk/lib/rdoc/rubygems_hook.rb#L173
     store.main     = options.main_page
     store.title    = options.title
 
-    @rdoc.store = RDoc::Store.new
+    @rdoc.store = store
 
     say "Parsing documentation for #{@spec.full_name}"
 
Index: test/rubygems/test_gem_rdoc.rb
===================================================================
--- test/rubygems/test_gem_rdoc.rb	(revision 38372)
+++ test/rubygems/test_gem_rdoc.rb	(revision 38373)
@@ -43,7 +43,7 @@ class TestGemRDoc < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L43
   end
 
   def test_initialize
-    assert @hook.generate_rdoc
+    refute @hook.generate_rdoc
     assert @hook.generate_ri
 
     rdoc = Gem::RDoc.new @a, false, false
Index: test/rdoc/test_rdoc_rubygems_hook.rb
===================================================================
--- test/rdoc/test_rdoc_rubygems_hook.rb	(revision 38372)
+++ test/rdoc/test_rdoc_rubygems_hook.rb	(revision 38373)
@@ -10,7 +10,15 @@ class TestRDocRubygemsHook < Gem::TestCa https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rubygems_hook.rb#L10
     skip 'requires RubyGems 1.9+' unless
       Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.9')
 
-    @a = quick_spec 'a'
+    @a = quick_spec 'a' do |s|
+      s.rdoc_options = %w[--main MyTitle]
+      s.extra_rdoc_files = %w[README]
+    end
+
+    write_file File.join(@tempdir, 'lib', 'a.rb')
+    write_file File.join(@tempdir, 'README')
+
+    install_gem @a
 
     @hook = RDoc::RubygemsHook.new @a
 
@@ -24,7 +32,7 @@ class TestRDocRubygemsHook < Gem::TestCa https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rubygems_hook.rb#L32
   end
 
   def test_initialize
-    assert @hook.generate_rdoc
+    refute @hook.generate_rdoc
     assert @hook.generate_ri
 
     rdoc = RDoc::RubygemsHook.new @a, false, false
@@ -66,12 +74,37 @@ class TestRDocRubygemsHook < Gem::TestCa https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rubygems_hook.rb#L74
 
     @hook.generate
 
+    refute @hook.rdoc_installed?
+    assert @hook.ri_installed?
+
+    rdoc = @hook.instance_variable_get :@rdoc
+
+    refute rdoc.options.hyperlink_all
+    assert_equal Pathname(@a.full_gem_path), rdoc.options.root
+    assert_equal %w[README lib], rdoc.options.files.sort
+
+    assert_equal 'MyTitle', rdoc.store.main
+  end
+
+  def test_generate_all
+    @hook.generate_rdoc = true
+    @hook.generate_ri   = true
+
+    FileUtils.mkdir_p @a.doc_dir
+    FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
+
+    @hook.generate
+
     assert @hook.rdoc_installed?
     assert @hook.ri_installed?
 
     rdoc = @hook.instance_variable_get :@rdoc
 
     refute rdoc.options.hyperlink_all
+    assert_equal Pathname(@a.full_gem_path), rdoc.options.root
+    assert_equal %w[README lib], rdoc.options.files.sort
+
+    assert_equal 'MyTitle', rdoc.store.main
   end
 
   def test_generate_configuration_rdoc_array
@@ -133,7 +166,7 @@ class TestRDocRubygemsHook < Gem::TestCa https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rubygems_hook.rb#L166
 
     @hook.generate
 
-    assert_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
+    refute_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
     assert_path_exists File.join(@a.doc_dir('ri'),   'cache.ri')
   end
 
@@ -183,7 +216,7 @@ class TestRDocRubygemsHook < Gem::TestCa https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rubygems_hook.rb#L216
 
     assert_equal @a.base_dir, e.directory
   ensure
-    FileUtils.chmod 0755, @a.base_dir
+    FileUtils.chmod(0755, @a.base_dir) if File.directory?(@a.base_dir)
   end
 
   def test_ri_installed?
@@ -202,20 +235,18 @@ class TestRDocRubygemsHook < Gem::TestCa https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rubygems_hook.rb#L235
 
   def test_setup_unwritable
     skip 'chmod not supported' if Gem.win_platform?
-    begin
-      FileUtils.mkdir_p @a.doc_dir
-      FileUtils.chmod 0, @a.doc_dir
+    FileUtils.mkdir_p @a.doc_dir
+    FileUtils.chmod 0, @a.doc_dir
+
+    e = assert_raises Gem::FilePermissionError do
+      @hook.setup
+    end
 
-      e = assert_raises Gem::FilePermissionError do
-        @hook.setup
-      end
-
-      assert_equal @a.doc_dir, e.directory
-    ensure
-      if File.exist? @a.doc_dir
-        FileUtils.chmod 0755, @a.doc_dir
-        FileUtils.rm_r @a.doc_dir
-      end
+    assert_equal @a.doc_dir, e.directory
+  ensure
+    if File.exist? @a.doc_dir
+      FileUtils.chmod 0755, @a.doc_dir
+      FileUtils.rm_r @a.doc_dir
     end
   end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]