我在Rails 5.2应用程序中使用以下宝石。
# /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一起工作?还是宝石有问题?
最佳答案
之所以引发该错误,是因为最新版本的Brakeman(4.5.1)将warning.file
的类从String
更改为Brakeman::FilePath
。guard-brakeman
确实应该一直使用Brakeman::Warning#relative_path
,但不幸的是it was (wrongly) removed in Brakeman 4.5.1。
简而言之,请暂时尝试固定到Brakeman 4.5.0,然后等待下一个Brakeman或后卫的Brakeman版本来解决此问题。
我已经打开https://github.com/guard/guard-brakeman/pull/36和https://github.com/presidentbeef/brakeman/pull/1365。
像这样的问题应该报告为项目的错误,而不是在StackOverflow上询问。
更新:guard-brakeman 0.8.4解决了此问题。