Skip to content

Commit

Permalink
Reduced diff with RubyGems::RDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Dec 14, 2012
1 parent 3a34c2c commit 9b0b5e5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
8 changes: 5 additions & 3 deletions lib/rdoc/rubygems_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ def self.load_rdoc

##
# 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
Expand Down
53 changes: 36 additions & 17 deletions test/test_rdoc_rubygems_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setup
end

def test_initialize
assert @hook.generate_rdoc
refute @hook.generate_rdoc
assert @hook.generate_ri

rdoc = RDoc::RubygemsHook.new @a, false, false
Expand Down Expand Up @@ -74,6 +74,27 @@ def test_generate

@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?

Expand Down Expand Up @@ -145,7 +166,7 @@ def test_generate_force

@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

Expand Down Expand Up @@ -195,7 +216,7 @@ def test_remove_unwritable

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?
Expand All @@ -214,20 +235,18 @@ def test_setup

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

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
FileUtils.mkdir_p @a.doc_dir
FileUtils.chmod 0, @a.doc_dir

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
end

Expand Down

0 comments on commit 9b0b5e5

Please sign in to comment.