Skip to content

Commit f25cee9

Browse files
committed
Test for RDoc::RI::DefaultDisplay, allow output stream to be set.
1 parent f92ce19 commit f25cee9

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

lib/rdoc/ri/display.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class RDoc::RI::DefaultDisplay
3232

3333
include RDoc::RI::Display
3434

35-
def initialize(formatter, width, use_stdout)
35+
def initialize(formatter, width, use_stdout, output = $stdout)
3636
@use_stdout = use_stdout
37-
@formatter = formatter.new $stdout, width, " "
37+
@formatter = formatter.new output, width, " "
3838
end
3939

4040
def display_method_info(method)

test/test_rdoc_ri_default_display.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
require 'stringio'
2+
require 'test/unit'
3+
require 'rdoc/ri/formatter'
4+
require 'rdoc/ri/display'
5+
require 'rdoc/ri/driver'
6+
7+
class TestRDocRIDefaultDisplay < Test::Unit::TestCase
8+
9+
def setup
10+
@output = StringIO.new
11+
@width = 78
12+
@indent = ' '
13+
14+
@dd = RDoc::RI::DefaultDisplay.new RDoc::RI::Formatter, @width, true,
15+
@output
16+
end
17+
18+
def test_display_class_info
19+
klass = {
20+
'attributes' => [
21+
{ 'name' => 'author', 'rw' => 'RW',
22+
'comment' => RDoc::Markup::Flow::P.new("<b>Recommended</b>: blah") },
23+
],
24+
'class_methods' => [],
25+
'class_method_extensions' => [],
26+
'constants' => [
27+
{ 'name' => 'VERSION', 'value' => '"1.5.1"',
28+
'comment' => RDoc::Markup::Flow::P.new('The version of Hoe') },
29+
],
30+
'display_name' => 'Class',
31+
'full_name' => 'Hoe',
32+
'includes' => [],
33+
'instance_methods' => [
34+
{ 'name' => 'developer' },
35+
{ 'name' => 'paragraphs_of' },
36+
],
37+
'instance_method_extensions' => [],
38+
'superclass_string' => 'Object',
39+
}
40+
ri_reader = nil
41+
42+
@dd.display_class_info klass, ri_reader
43+
44+
expected = <<-EOF
45+
---------------------------------------------------------- Class: Hoe < Object
46+
(no description...)
47+
------------------------------------------------------------------------------
48+
49+
50+
Constants:
51+
----------
52+
53+
VERSION: \"1.5.1\"
54+
55+
56+
Instance methods:
57+
-----------------
58+
59+
developer, paragraphs_of
60+
61+
Attributes:
62+
author
63+
EOF
64+
65+
assert_equal expected, @output.string
66+
end
67+
68+
end
69+

0 commit comments

Comments
 (0)