0

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

4

1 回答 1

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!
于 2013-07-05T13:44:05.590 回答