diff --git a/ChangeLog b/ChangeLog index d21c6dc051..612048f5af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Dec 14 14:16:42 2012 Eric Hodel + + * 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 * lib/rubygems/commands/rdoc_command.rb: When overwriting diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb index 9fcb783425..f001c6d66c 100644 --- a/lib/rdoc/rubygems_hook.rb +++ b/lib/rdoc/rubygems_hook.rb @@ -68,10 +68,12 @@ class RDoc::RubygemsHook ## # 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 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 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 store.main = options.main_page store.title = options.title - @rdoc.store = RDoc::Store.new + @rdoc.store = store say "Parsing documentation for #{@spec.full_name}" diff --git a/lib/rdoc/store.rb b/lib/rdoc/store.rb index 9beced6423..2a2acf4edb 100644 --- a/lib/rdoc/store.rb +++ b/lib/rdoc/store.rb @@ -596,7 +596,7 @@ class RDoc::Store 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 diff --git a/test/rdoc/test_rdoc_rubygems_hook.rb b/test/rdoc/test_rdoc_rubygems_hook.rb index beba030c94..da9c3edd9f 100644 --- a/test/rdoc/test_rdoc_rubygems_hook.rb +++ b/test/rdoc/test_rdoc_rubygems_hook.rb @@ -10,7 +10,15 @@ class TestRDocRubygemsHook < Gem::TestCase 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::TestCase 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::TestCase @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::TestCase @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::TestCase 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::TestCase 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 diff --git a/test/rubygems/test_gem_rdoc.rb b/test/rubygems/test_gem_rdoc.rb index 2d279e3372..bece6a1782 100644 --- a/test/rubygems/test_gem_rdoc.rb +++ b/test/rubygems/test_gem_rdoc.rb @@ -43,7 +43,7 @@ class TestGemRDoc < Gem::TestCase end def test_initialize - assert @hook.generate_rdoc + refute @hook.generate_rdoc assert @hook.generate_ri rdoc = Gem::RDoc.new @a, false, false