我在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一起工作?还是宝石有问题?
答案 0 :(得分:2)
由于最新版本的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或Guard-Brakeman版本来解决此问题。
我已经打开https://github.com/guard/guard-brakeman/pull/36和https://github.com/presidentbeef/brakeman/pull/1365。
类似这样的问题应该被报告为项目的错误,而不是在StackOverflow上被询问。