我很惊讶地发现警告在 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
除了在代码的早期设置之外,是否有一种简单的方法来启用它们?