Class: RDoc::TestCase

Inherits:
MiniTest::Unit::TestCase
  • Object
show all
Defined in:
lib/rdoc/test_case.rb

Overview

RDoc::TestCase is an abstract TestCase to provide common setup and teardown across all RDoc tests. The test case uses minitest, so all the assertions of minitest may be used.

The testcase provides the following:

  • A reset code-object tree

  • A reset markup preprocessor (RDoc::Markup::PreProcess)

  • The @RM alias of RDoc::Markup (for less typing)

  • @pwd containing the current working directory

  • FileUtils, pp, Tempfile, Dir.tmpdir and StringIO

Direct Known Subclasses

Markup::FormatterTestCase

Instance Method Summary collapse

Instance Method Details

#blank_lineObject

Shortcut for RDoc::Markup::BlankLine.new



58
59
60
# File 'lib/rdoc/test_case.rb', line 58

def blank_line
  @RM::BlankLine.new
end

#block(*contents) ⇒ Object

Shortcut for RDoc::Markup::BlockQuote.new with contents



65
66
67
# File 'lib/rdoc/test_case.rb', line 65

def block *contents
  @RM::BlockQuote.new(*contents)
end

#comment(text, top_level = @top_level) ⇒ Object

Creates an RDoc::Comment with text which was defined on top_level. By default the comment has the ‘rdoc’ format.



73
74
75
# File 'lib/rdoc/test_case.rb', line 73

def comment text, top_level = @top_level
  RDoc::Comment.new text, top_level
end

#doc(*contents) ⇒ Object

Shortcut for RDoc::Markup::Document.new with contents



80
81
82
# File 'lib/rdoc/test_case.rb', line 80

def doc *contents
  @RM::Document.new(*contents)
end

#hard_breakObject

Shortcut for RDoc::Markup::HardBreak.new



87
88
89
# File 'lib/rdoc/test_case.rb', line 87

def hard_break
  @RM::HardBreak.new
end

#head(level, text) ⇒ Object

Shortcut for RDoc::Markup::Heading.new with level and text



94
95
96
# File 'lib/rdoc/test_case.rb', line 94

def head level, text
  @RM::Heading.new level, text
end

#item(label = nil, *parts) ⇒ Object

Shortcut for RDoc::Markup::ListItem.new with label and parts



101
102
103
# File 'lib/rdoc/test_case.rb', line 101

def item label = nil, *parts
  @RM::ListItem.new label, *parts
end

#list(type = nil, *items) ⇒ Object

Shortcut for RDoc::Markup::List.new with type and items



108
109
110
# File 'lib/rdoc/test_case.rb', line 108

def list type = nil, *items
  @RM::List.new type, *items
end

#para(*a) ⇒ Object

Shortcut for RDoc::Markup::Paragraph.new with contents



115
116
117
# File 'lib/rdoc/test_case.rb', line 115

def para *a
  @RM::Paragraph.new(*a)
end

#raw(*contents) ⇒ Object

Shortcut for RDoc::Markup::Raw.new with contents



129
130
131
# File 'lib/rdoc/test_case.rb', line 129

def raw *contents
  @RM::Raw.new(*contents)
end

#rule(weight) ⇒ Object

Shortcut for RDoc::Markup::Rule.new with weight



122
123
124
# File 'lib/rdoc/test_case.rb', line 122

def rule weight
  @RM::Rule.new weight
end

#setupObject

Abstract test-case setup



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rdoc/test_case.rb', line 31

def setup
  super

  @top_level = nil

  @have_encoding = Object.const_defined? :Encoding

  @RM = RDoc::Markup

  RDoc::Markup::PreProcess.reset

  @pwd = Dir.pwd

  @store = RDoc::Store.new

  @rdoc = RDoc::RDoc.new
  @rdoc.store = @store

  g = Object.new
  def g.class_dir() end
  def g.file_dir() end
  @rdoc.generator = g
end

#temp_dirObject

Creates a temporary directory changes the current directory to it for the duration of the block.

Depends upon Dir.mktmpdir



139
140
141
142
143
144
145
146
147
# File 'lib/rdoc/test_case.rb', line 139

def temp_dir
  skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir

  Dir.mktmpdir do |temp_dir|
    Dir.chdir temp_dir do
      yield temp_dir
    end
  end
end

#verb(*parts) ⇒ Object

Shortcut for RDoc::Markup::Verbatim.new with parts



152
153
154
# File 'lib/rdoc/test_case.rb', line 152

def verb *parts
  @RM::Verbatim.new(*parts)
end

#verbose_capture_ioObject

run capture_io with setting $VERBOSE = true



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/rdoc/test_case.rb', line 159

def verbose_capture_io
  capture_io do
    begin
      orig_verbose = $VERBOSE
      $VERBOSE = true
      yield
    ensure
      $VERBOSE = orig_verbose
    end
  end
end