我很惊讶地发现rake默认禁用警告:
def broken_code
path = '/tmp/foo'
# create empty file
File.open(path, 'w')
# when warnings are enabled you get a warning here- File#new does not take a block
File.new(path) do |f|
puts "never get here..."
end
end
task :no_warnings do |t|
broken_code
end
task :warnings do |t|
$VERBOSE = 1
broken_code
end
为什么他们被禁用?除了在代码的早期设置VERBOSE=1
之外,是否有一种简单的方法来启用它们?
答案 0 :(得分:2)
它对我有用:
# Rakefile
task :foo do |t|
File.new {}
end
结果:
$ rake foo
(in /tmp)
/tmp/Rakefile:2: warning: File::new() does not take block; use File::open() instead
rake aborted!