1require File.expand_path('../helper', __FILE__) 2 3class TestRakeDsl < Rake::TestCase 4 5 def setup 6 super 7 Rake::Task.clear 8 end 9 10 def test_namespace_command 11 namespace "n" do 12 task "t" 13 end 14 refute_nil Rake::Task["n:t"] 15 end 16 17 def test_namespace_command_with_bad_name 18 ex = assert_raises(ArgumentError) do 19 namespace 1 do end 20 end 21 assert_match(/string/i, ex.message) 22 assert_match(/symbol/i, ex.message) 23 end 24 25 def test_namespace_command_with_a_string_like_object 26 name = Object.new 27 def name.to_str 28 "bob" 29 end 30 namespace name do 31 task "t" 32 end 33 refute_nil Rake::Task["bob:t"] 34 end 35 36 class Foo 37 def initialize 38 task :foo_deprecated_a => "foo_deprecated_b" do 39 print "a" 40 end 41 file "foo_deprecated_b" do 42 print "b" 43 end 44 end 45 end 46 47 def test_deprecated_object_dsl 48 out, err = capture_io do 49 Foo.new 50 Rake.application.invoke_task :foo_deprecated_a 51 end 52 assert_equal("ba", out) 53 assert_match(/deprecated/, err) 54 assert_match(/Foo\#task/, err) 55 assert_match(/Foo\#file/, err) 56 assert_match(/test_rake_dsl\.rb:\d+/, err) 57 end 58 59 def test_no_commands_constant 60 assert ! defined?(Commands), "should not define Commands" 61 end 62 63 def test_deprecated_object_dsl_with_suppressed_warnings 64 Rake.application.options.ignore_deprecate = true 65 out, err = capture_io do 66 Foo.new 67 Rake.application.invoke_task :foo_deprecated_a 68 end 69 assert_equal("ba", out) 70 refute_match(/deprecated/, err) 71 refute_match(/Foo\#task/, err) 72 refute_match(/Foo\#file/, err) 73 refute_match(/test_rake_dsl\.rb:\d+/, err) 74 ensure 75 Rake.application.options.ignore_deprecate = false 76 end 77end 78