Why is brakeman-guard raising "NoMethodError: undefined method `gsub'"

Why is brakeman-guard raising "NoMethodError: undefined method `gsub'"

我在 Rails 5.2 应用程序中使用以下 gems。

# /Gemfile

group :development do

  gem 'guard'
  gem 'guard-spring'
  gem 'guard-rspec'
  gem 'brakeman', require: false
  gem 'guard-brakeman'

  # ...

end

# ...

Brakeman 与 Guard 配合得很好,但最近发生了一些变化。

> bundle exec guard 

... usual startup trace 

------ brakeman warnings --------
00:52:13 - INFO - 6 brakeman findings
00:52:13 - ERROR - Guard::Brakeman failed to achieve its <start>, exception was:
> [#8fe733251410] NoMethodError: undefined method `gsub' for #<Brakeman::FilePath:0x00007f8d0f2c9ea0>
> [#8fe733251410] /Users/me/.rvm/gems/ruby-2.5.3@myapp/gems/guard-brakeman-0.8.3/lib/guard/brakeman.rb:206:in `decorate_warning'

...

00:52:13 - INFO - Guard::Brakeman has just been fired

查看 gem repo,在引发此错误的行附近有一条评论

/lib/guard/brakeman.rb
# ...
# line 206
output << " near line #{warning.line}" if warning.line
if warning.file
  # fix this ish or wait for brakeman to be fixed
  filename = warning.file.gsub(@options[:app_path], '')
  # ...

还有其他人遇到这个问题吗?我是否错误地配置了我的应用程序,这会阻止 Brakeman 使用 Guard?还是 gem 有问题?

它引发了这个错误,因为最新版本的 Brakeman (4.5.1) 将 warning.file 的 class 从 String 更改为 Brakeman::FilePath

guard-brakeman 真的应该一直使用 Brakeman::Warning#relative_path,但不幸的是 it was (wrongly) removed in Brakeman 4.5.1.

简而言之,请暂时固定到 Brakeman 4.5.0 并等待下一个 Brakeman 或 guard-brakeman 版本来解决此问题。

我打开了https://github.com/guard/guard-brakeman/pull/36 and https://github.com/presidentbeef/brakeman/pull/1365.

像这样的问题可能应该作为错误报告给项目,而不是在 Whosebug 上询问。

更新:guard-brakeman 0.8.4 修复了这个问题。