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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
require File.expand_path('../helper', __FILE__)
class TestRakeTopLevelFunctions < Rake::TestCase
def setup
super
@app = Object.new
def @app.called
@called
end
def @app.method_missing(*a, &b)
@called ||= []
@called << [a, b]
nil
end
Rake.application = @app
end
def test_namespace
block = proc do end
namespace("xyz", &block)
expected = [
[[:in_namespace, 'xyz'], block]
]
assert_equal expected, @app.called
end
def test_import
import('x', 'y', 'z')
expected = [
[[:add_import, 'x'], nil],
[[:add_import, 'y'], nil],
[[:add_import, 'z'], nil],
]
assert_equal expected, @app.called
end
def test_when_writing
out, = capture_io do
when_writing("NOTWRITING") do
puts "WRITING"
end
end
assert_equal "WRITING\n", out
end
def test_when_not_writing
Rake::FileUtilsExt.nowrite_flag = true
_, err = capture_io do
when_writing("NOTWRITING") do
puts "WRITING"
end
end
assert_equal "DRYRUN: NOTWRITING\n", err
ensure
Rake::FileUtilsExt.nowrite_flag = false
end
def test_missing_constants_task
Object.const_missing(:Task)
expected = [
[[:const_warning, :Task], nil]
]
assert_equal expected, @app.called
end
def test_missing_constants_file_task
Object.const_missing(:FileTask)
expected = [
[[:const_warning, :FileTask], nil]
]
assert_equal expected, @app.called
end
def test_missing_constants_file_creation_task
Object.const_missing(:FileCreationTask)
expected = [
[[:const_warning, :FileCreationTask], nil]
]
assert_equal expected, @app.called
end
def test_missing_constants_rake_app
Object.const_missing(:RakeApp)
expected = [
[[:const_warning, :RakeApp], nil]
]
assert_equal expected, @app.called
end
def test_missing_other_constant
assert_raises(NameError) do Object.const_missing(:Xyz) end
end
end
|