--I want to execute tests and static analysis automatically --You can use git hooks to execute a specific script at the timing of commit, push, etc. --The contents of git hooks cannot be managed by git --Overcommit allows you to manage and extend git hooks
--Rspec (test automation) --Brakeman (security check) --Rubocop (Ruby code analysis) --RailsBestPractices (Rails code analysis)
I will write on the assumption that you have already installed and are ready to type commands manually. If you have a tool that you are not using, ignore the settings in that part.
Gemfile
group :development do
gem 'overcommit'
$ bundle install
$ overcommit --install #Generate configuration file
.overcommit.yml
#Disable unnecessary checks
CommitMsg:
ALL:
enabled: false
PreCommit:
AuthorEmail:
enabled: false
AuthorName:
enabled: false
BrokenSymlinks:
enabled: false
CaseConflicts:
enabled: false
MergeConflicts:
enabled: false
#Required check settings
RuboCop:
enabled: true
RailsBestPractices:
enabled: true
PrePush:
Brakeman:
enabled: true
RSpec:
enabled: true
$ overcommit --sign #Reflect the setting change
Default settings is applied except for the items explicitly set in the configuration file.
The following is an example of the operation check method.
Rubocop
Embed Time.now
in a suitable controller and confirm that it cannot be committed
RailsBestPractices
Set default_scope order (created_at:: desc)
to an appropriate model and confirm that you cannot commit
Brakeman
Set http_basic_authenticate_with name:'ID', password:'password'
to the appropriate controller and confirm that Push is not possible.
RSpec
Write a test that doesn't pass and make sure you can't push
When I run RSpec manually, it passes, but the pre-push check fails and I get the following message:
NameError:
uninitialized constant Capybara::DSL
When I hit it manually, I'm running bin / rspec
, but when I'm pre-pushing, I'm running bundle exec rspec
, so it seems that the behavior is slightly different. Solved by adding the following to spec_helper.rb
.
spec/spec_helper.rb
RSpec.configure do |config|
#Added the following 3 lines
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
require 'rspec/rails'
Recommended Posts