-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_case.rb
76 lines (58 loc) · 1.71 KB
/
test_case.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'rubygems'
require 'minitest/autorun'
require 'minitest/benchmark' if ENV['BENCHMARK']
require 'fileutils'
require 'pp'
require 'tempfile'
require 'tmpdir'
require 'stringio'
require 'rdoc'
##
# 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 <code>@RM</code> alias of RDoc::Markup (for less typing)
# * <code>@pwd</code> containing the current working directory
# * FileUtils, pp, Tempfile, Dir.tmpdir and StringIO
class RDoc::TestCase < MiniTest::Unit::TestCase
##
# Abstract test-case setup
def setup
super
@top_level = nil
@RM = RDoc::Markup
RDoc::RDoc.reset
RDoc::Markup::PreProcess.reset
@pwd = Dir.pwd
end
##
# Creates an RDoc::Comment with +text+ which was defined on +top_level+.
# By default the comment has the 'rdoc' format.
def comment text, top_level = @top_level
RDoc::Comment.new text, top_level
end
##
# Creates a temporary directory changes the current directory to it for the
# duration of the block.
#
# Depends upon Dir.mktmpdir
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
end
# This hack allows autoload to work when Dir.pwd is changed for Ruby 1.8 since
# -I paths are not expanded.
$LOAD_PATH.each do |load_path|
break if load_path[0] == ?/
load_path.replace File.expand_path load_path
end if RUBY_VERSION < '1.9'