test/test_application.rb in jimweirich-rake-0.8.3.1 vs test/test_application.rb in jimweirich-rake-0.8.3.99
- old
+ new
@@ -16,10 +16,11 @@
######################################################################
class TestApplication < Test::Unit::TestCase
include CaptureStdout
include InEnvironment
+ include TestMethods
def setup
@app = Rake::Application.new
@app.options.rakelib = []
end
@@ -107,11 +108,11 @@
assert_match(/^rake t$/, out)
assert_match(/^ {4}COMMENT$/, out)
end
def test_finding_rakefile
- assert_match(/[Rr]akefile/, @app.instance_eval { have_rakefile })
+ assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
end
def test_not_finding_rakefile
@app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
assert( ! @app.instance_eval do have_rakefile end )
@@ -146,11 +147,11 @@
in_environment("PWD" => "/", "RAKE_SYSTEM" => 'not_exist') do
@app.instance_eval do
handle_options
options.silent = true
end
- ex = assert_raise(RuntimeError) do
+ ex = assert_exception(RuntimeError) do
@app.instance_eval do raw_load_rakefile end
end
assert_match(/no rakefile found/i, ex.message)
end
end
@@ -160,30 +161,32 @@
@app.options.rakelib = []
@app.instance_eval do
handle_options
options.silent = true
options.load_system = true
+ options.rakelib = []
load_rakefile
end
assert_equal "test/data/sys", @app.system_dir
assert_nil @app.rakefile
end
end
def test_load_from_system_rakefile_on_unix
- flexmock(@app, :windows? => false,
- :win32_system_dir => nil,
- :load => nil)
+ flexmock(Rake::Win32, :windows? => false,
+ :win32_system_dir => nil)
+ flexmock(@app, :load => nil)
flexmock(File).should_receive(:expand_path).with("~").and_return("/HOME")
flexmock(File).should_receive(:expand_path).and_return { |fn| fn }
in_environment('RAKE_SYSTEM' => nil) do
@app.options.rakelib = []
@app.instance_eval do
handle_options
options.silent = true
options.load_system = true
+ options.rakelib = []
load_rakefile
end
assert_equal "/HOME/.rake", @app.system_dir
end
end
@@ -193,21 +196,22 @@
end
def test_load_from_system_rakefile_on_windows
flexmock(Rake::Win32, :windows? => true)
flexmock(@app, :standard_system_dir => "XX")
- flexmock(@app).should_receive(:directory?).with("/AD/Rake").and_return(true)
flexmock(@app).should_receive(:load).and_return(nil)
- in_environment('RAKE_SYSTEM' => nil, 'APPDATA' => '/AD') do
+ flexmock(File).should_receive(:directory?).with("D:/AD/Rake").and_return(true)
+ in_environment('RAKE_SYSTEM' => nil, 'HOME' => nil, 'HOMEDRIVE' => 'D:', 'HOMEPATH' => '\\AD') do
@app.options.rakelib = []
@app.instance_eval do
handle_options
options.silent = true
options.load_system = true
+ options.rakelib = []
load_rakefile
end
- assert_equal "/AD/Rake", @app.system_dir
+ assert_equal "D:/AD/Rake", @app.system_dir
end
end
def test_loading_imports
mock = flexmock("loader")
@@ -229,10 +233,23 @@
add_import("x.dummy")
load_imports
end
end
+ def test_handle_options__should_strip_options_from_ARGV
+ assert !@app.options.trace
+
+ valid_option = '--trace'
+ ARGV.clear
+ ARGV << valid_option
+
+ @app.handle_options
+
+ assert !ARGV.include?(valid_option)
+ assert @app.options.trace
+ end
+
def test_good_run
ran = false
ARGV.clear
ARGV << '--rakelib=""'
@app.options.silent = true
@@ -277,11 +294,11 @@
def test_bad_run
@app.intern(Rake::Task, "default").enhance { fail }
ARGV.clear
ARGV << '-f' << '-s' << '--rakelib=""'
- assert_raise(SystemExit) {
+ assert_exception(SystemExit) {
err = capture_stderr { @app.run }
assert_match(/see full trace/, err)
}
ensure
ARGV.clear
@@ -289,11 +306,11 @@
def test_bad_run_with_trace
@app.intern(Rake::Task, "default").enhance { fail }
ARGV.clear
ARGV << '-f' << '-s' << '-t'
- assert_raise(SystemExit) {
+ assert_exception(SystemExit) {
err = capture_stderr { capture_stdout { @app.run } }
assert_no_match(/see full trace/, err)
}
ensure
ARGV.clear
@@ -301,11 +318,11 @@
def test_run_with_bad_options
@app.intern(Rake::Task, "default").enhance { fail }
ARGV.clear
ARGV << '-f' << '-s' << '--xyzzy'
- assert_raise(SystemExit) {
+ assert_exception(SystemExit) {
err = capture_stderr { capture_stdout { @app.run } }
}
ensure
ARGV.clear
end
@@ -313,10 +330,11 @@
######################################################################
class TestApplicationOptions < Test::Unit::TestCase
include CaptureStdout
+ include TestMethods
def setup
clear_argv
RakeFileUtils.verbose_flag = false
RakeFileUtils.nowrite_flag = false
@@ -445,11 +463,11 @@
assert TESTING_REQUIRE.include?(3)
assert_equal 3, TESTING_REQUIRE.size
end
def test_missing_require
- ex = assert_raises(LoadError) do
+ ex = assert_exception(LoadError) do
flags(['--require', 'test/missing']) do |opts|
end
end
assert_match(/no such file/, ex.message)
assert_match(/test\/missing/, ex.message)
@@ -544,11 +562,11 @@
end
end
def test_bad_option
capture_stderr do
- ex = assert_raise(OptionParser::InvalidOption) do
+ ex = assert_exception(OptionParser::InvalidOption) do
flags('--bad-option')
end
if ex.message =~ /^While/ # Ruby 1.9 error message
assert_match(/while parsing/i, ex.message)
else # Ruby 1.8 error message
@@ -592,10 +610,11 @@
@app = Rake::Application.new
def @app.exit(*args)
throw :system_exit, :exit
end
@app.instance_eval do
- collect_tasks handle_options
+ handle_options
+ collect_tasks
end
@tasks = @app.top_level_tasks
@app.options
end
end