I'm using the following gems in a Rails 5.2 app.
# /Gemfile
group :development do
gem 'guard'
gem 'guard-spring'
gem 'guard-rspec'
gem 'brakeman', require: false
gem 'guard-brakeman'
# ...
end
# ...
Brakeman was working fine with Guard, but recently something has changed.
> 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
Looking at the gem repo, there is a comment near the line raising this error
/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], '')
# ...
Is anyone else experiencing this issue? Have I configured my app incorrectly and this is preventing Brakeman working with Guard? Or is there an issue in the gem?
It's raising that error because the latest version of Brakeman (4.5.1) changed the class of warning.file
from a String
to a Brakeman::FilePath
.
guard-brakeman
really should have been using Brakeman::Warning#relative_path
all along, but unfortunately it was (wrongly) removed in Brakeman 4.5.1.
In short, please try pinning to Brakeman 4.5.0 for now and wait for either the next Brakeman or guard-brakeman release to address this issue.
I have opened https://github.com/guard/guard-brakeman/pull/36 and https://github.com/presidentbeef/brakeman/pull/1365.
Issues like this should probably be reported as bugs to the projects instead of being asked on StackOverflow.
Update: guard-brakeman 0.8.4 fixes this issue.