forked from ruby/rake
/
test_top_level_functions.rb
84 lines (70 loc) · 1.94 KB
/
test_top_level_functions.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
76
77
78
79
80
81
82
83
84
#!/usr/bin/env ruby
begin
require 'rubygems'
rescue LoadError
# got no gems
end
require 'test/unit'
require 'test/capture_stdout'
require 'rake'
require 'flexmock/test_unit'
class TestTopLevelFunctions < Test::Unit::TestCase
include CaptureStdout
def setup
super
@app = Rake.application
Rake.application = flexmock("app")
end
def teardown
Rake.application = @app
super
end
def test_namespace
Rake.application.should_receive(:in_namespace).with("xyz", any).once
namespace "xyz" do end
end
def test_import
Rake.application.should_receive(:add_import).with("x").once.ordered
Rake.application.should_receive(:add_import).with("y").once.ordered
Rake.application.should_receive(:add_import).with("z").once.ordered
import('x', 'y', 'z')
end
def test_when_writing
out = capture_stdout do
when_writing("NOTWRITING") do
puts "WRITING"
end
end
assert_equal "WRITING\n", out
end
def test_when_not_writing
RakeFileUtils.nowrite_flag = true
out = capture_stdout do
when_writing("NOTWRITING") do
puts "WRITING"
end
end
assert_equal "DRYRUN: NOTWRITING\n", out
ensure
RakeFileUtils.nowrite_flag = false
end
def test_missing_constants_task
Rake.application.should_receive(:const_warning).with(:Task).once
Object.const_missing(:Task)
end
def test_missing_constants_file_task
Rake.application.should_receive(:const_warning).with(:FileTask).once
Object.const_missing(:FileTask)
end
def test_missing_constants_file_creation_task
Rake.application.should_receive(:const_warning).with(:FileCreationTask).once
Object.const_missing(:FileCreationTask)
end
def test_missing_constants_rake_app
Rake.application.should_receive(:const_warning).with(:RakeApp).once
Object.const_missing(:RakeApp)
end
def test_missing_other_constant
assert_raise(NameError) do Object.const_missing(:Xyz) end
end
end