1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/rake/test_extension.rb
nobu 719b0f8e30 * lib/rake: updated to rake code to rake-0.8.7 source code base.
* lib/rake/loaders/makefile.rb (Rake::MakefileLoader#process_line):
  respace dependencies too.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-02 19:07:55 +00:00

61 lines
1.2 KiB
Ruby

require 'test/unit'
require 'rake'
require 'stringio'
######################################################################
class TestExtension < Test::Unit::TestCase
module Redirect
def error_redirect
old_err = $stderr
result = StringIO.new
$stderr = result
yield
result
ensure
$stderr = old_err
end
end
class Sample
extend Redirect
def duplicate_method
:original
end
OK_ERRS = error_redirect do
rake_extension("a") do
def ok_method
end
end
end
DUP_ERRS = error_redirect do
rake_extension("duplicate_method") do
def duplicate_method
:override
end
end
end
end
def test_methods_actually_exist
sample = Sample.new
sample.ok_method
sample.duplicate_method
end
def test_no_warning_when_defining_ok_method
assert_equal "", Sample::OK_ERRS.string
end
def test_extension_complains_when_a_method_that_is_present
assert_match(/warning:/i, Sample::DUP_ERRS.string)
assert_match(/already exists/i, Sample::DUP_ERRS.string)
assert_match(/duplicate_method/i, Sample::DUP_ERRS.string)
assert_equal :original, Sample.new.duplicate_method
end
end