.*]m]
assert_match(%r[Klass/Inner\.html".*>Inner<], summary)
end
def test_generate_page
@store.add_file 'outer.rdoc', parser: RDoc::Parser::Simple
@store.add_file 'outer/inner.rdoc', parser: RDoc::Parser::Simple
@g.generate
assert_file 'outer_rdoc.html'
assert_file 'outer/inner_rdoc.html'
index = File.read('index.html')
re = %r[outer.*?]m
assert_match(re, index)
summary = index[re]
assert_match %r[inner], summary
re = %r[outer
.*? ]m
assert_match(re, File.read('outer_rdoc.html'))
re = %r[outer
.*? ]m
assert_match(re, File.read('outer/inner_rdoc.html'))
end
def test_generate_dry_run
@g.dry_run = true
top_level = @store.add_file 'file.rb'
top_level.add_class @klass.class, @klass.name
@g.generate
refute_file 'index.html'
refute_file 'Object.html'
end
def test_generate_static
FileUtils.mkdir_p 'dir/images'
FileUtils.touch 'dir/images/image.png'
FileUtils.mkdir_p 'file'
FileUtils.touch 'file/file.txt'
@options.static_path = [
File.expand_path('dir'),
File.expand_path('file/file.txt'),
]
@g.generate
assert_file 'images/image.png'
assert_file 'file.txt'
end
def test_generate_static_dry_run
FileUtils.mkdir 'static'
FileUtils.touch 'static/image.png'
@options.static_path = [File.expand_path('static')]
@g.dry_run = true
@g.generate
refute_file 'image.png'
end
def test_install_rdoc_static_file
src = Pathname File.expand_path(__FILE__, @pwd)
dst = File.join @tmpdir, File.basename(src)
options = {}
@g.install_rdoc_static_file src, dst, options
assert_file dst
assert_hard_link dst
end
def test_install_rdoc_static_file_missing
src = Pathname(__FILE__) + 'nonexistent'
dst = File.join @tmpdir, File.basename(src)
options = {}
@g.install_rdoc_static_file src, dst, options
refute_file dst
end
def test_setup
@g.setup
assert_equal [@klass_alias, @ignored, @klass, @object],
@g.classes.sort_by { |klass| klass.full_name }
assert_equal [@top_level], @g.files
assert_equal [@meth, @meth, @meth_bang, @meth_bang, @meth_with_html_tag_yield, @meth_with_html_tag_yield], @g.methods
assert_equal [@klass_alias, @klass, @object], @g.modsort
end
def test_template_for
classpage = Pathname.new @options.template_dir + 'class.rhtml'
template = @g.send(:template_for, classpage, true, RDoc::ERBIO)
assert_kind_of RDoc::ERBIO, template
assert_same template, @g.send(:template_for, classpage)
end
def test_template_for_dry_run
classpage = Pathname.new @options.template_dir + 'class.rhtml'
template = @g.send(:template_for, classpage, true, ERB)
assert_kind_of ERB, template
assert_same template, @g.send(:template_for, classpage)
end
def test_template_for_partial
partial = Pathname.new @options.template_dir + '_sidebar_classes.rhtml'
template = @g.send(:template_for, partial, false, RDoc::ERBPartial)
assert_kind_of RDoc::ERBPartial, template
assert_same template, @g.send(:template_for, partial)
end
def test_generated_method_with_html_tag_yield
top_level = @store.add_file 'file.rb'
top_level.add_class @klass.class, @klass.name
@g.generate
path = File.join @tmpdir, 'A.html'
f = open(path)
internal_file = f.read
method_name_index = internal_file.index('method_with_html_tag_yield')
last_of_method_name_index = method_name_index + internal_file[method_name_index..-1].index('') - 1
method_name = internal_file[method_name_index..last_of_method_name_index]
f.close
assert_includes method_name, '{ |%<<script>alert("atui")</script>>, yield_arg| ... }'
end
def test_template_stylesheets
css = Tempfile.create(%W'hoge .css', Dir.mktmpdir('tmp', '.'))
File.write(css, '')
css.close
base = File.basename(css)
refute_file(base)
@options.template_stylesheets << css
@g.generate
assert_file base
assert_include File.read('index.html'), %Q[href="./#{base}"]
end
##
# Asserts that +filename+ has a link count greater than 1 if hard links to
# @tmpdir are supported.
def assert_hard_link filename
assert_file filename
src = @g.template_dir + '_head.rhtml'
dst = File.join @tmpdir, 'hardlinktest'
begin
FileUtils.ln src, dst
nlink = File.stat(dst).nlink if File.identical? src, dst
FileUtils.rm dst
return if nlink == 1
rescue SystemCallError
return
end
assert_operator File.stat(filename).nlink, :>, 1,
"#{filename} is not hard-linked"
end
end