Skip to content

Commit

Permalink
Improved deprecated DSL method warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Jun 1, 2011
1 parent a643163 commit f73cde7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/rake/dsl_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ module DeprecatedObjectDSL
dsl = Object.new.extend DSL
DSL.private_instance_methods(false).each do |name|
define_method name do |*args, &block|
$stderr.puts "WARNING: Relying upon the Rake DSL being accessible " <<
"everywhere is deprecated. Include Rake::DSL into classes which " <<
"use the Rake DSL methods. (#{self.class}##{name} called.)"
unless @dsl_warning
$stderr.puts "WARNING: Global access to rake DSL methods is deprecated."
$stderr.puts " ... Please Include Rake::DSL into classes which use the Rake DSL methods."
@dsl_warning = true
end
$stderr.puts "WARNING: DSL method #{self.class}##{name} called at #{caller.first}"
dsl.send(name, *args, &block)
end
private name
Expand Down
6 changes: 4 additions & 2 deletions test/test_rake_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def name.to_str

class Foo
def initialize
task :foo_deprecated_a => :foo_deprecated_b do
task :foo_deprecated_a => "foo_deprecated_b" do
print "a"
end
task :foo_deprecated_b do
file "foo_deprecated_b" do
print "b"
end
end
Expand All @@ -47,5 +47,7 @@ def test_deprecated_object_dsl
assert_equal("ba", out)
assert_match(/deprecated/, err)
assert_match(/Foo\#task/, err)
assert_match(/Foo\#file/, err)
assert_match(/test_rake_dsl\.rb:\d+/, err)
end
end

0 comments on commit f73cde7

Please sign in to comment.