2011-06-23 18:11:55 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
|
|
|
|
|
|
|
class TestRakeTopLevelFunctions < Rake::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2011-07-23 01:38:50 -04:00
|
|
|
@app = Object.new
|
2011-06-23 18:11:55 -04:00
|
|
|
|
2011-07-23 01:38:50 -04:00
|
|
|
def @app.called
|
|
|
|
@called
|
|
|
|
end
|
2011-06-23 18:11:55 -04:00
|
|
|
|
2011-07-23 01:38:50 -04:00
|
|
|
def @app.method_missing(*a, &b)
|
|
|
|
@called ||= []
|
|
|
|
@called << [a, b]
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
Rake.application = @app
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_namespace
|
2011-07-23 01:38:50 -04:00
|
|
|
block = proc do end
|
|
|
|
|
|
|
|
namespace("xyz", &block)
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
[[:in_namespace, 'xyz'], block]
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, @app.called
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_import
|
|
|
|
import('x', 'y', 'z')
|
2011-07-23 01:38:50 -04:00
|
|
|
|
|
|
|
expected = [
|
|
|
|
[[:add_import, 'x'], nil],
|
|
|
|
[[:add_import, 'y'], nil],
|
|
|
|
[[:add_import, 'z'], nil],
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, @app.called
|
2011-06-23 18:11:55 -04:00
|
|
|
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)
|
2011-07-23 01:38:50 -04:00
|
|
|
|
|
|
|
expected = [
|
|
|
|
[[:const_warning, :Task], nil]
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, @app.called
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_missing_constants_file_task
|
|
|
|
Object.const_missing(:FileTask)
|
2011-07-23 01:38:50 -04:00
|
|
|
|
|
|
|
expected = [
|
|
|
|
[[:const_warning, :FileTask], nil]
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, @app.called
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_missing_constants_file_creation_task
|
|
|
|
Object.const_missing(:FileCreationTask)
|
2011-07-23 01:38:50 -04:00
|
|
|
|
|
|
|
expected = [
|
|
|
|
[[:const_warning, :FileCreationTask], nil]
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, @app.called
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_missing_constants_rake_app
|
|
|
|
Object.const_missing(:RakeApp)
|
2011-07-23 01:38:50 -04:00
|
|
|
|
|
|
|
expected = [
|
|
|
|
[[:const_warning, :RakeApp], nil]
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, @app.called
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_missing_other_constant
|
|
|
|
assert_raises(NameError) do Object.const_missing(:Xyz) end
|
|
|
|
end
|
|
|
|
end
|