Look for last version or use this:
gem 'rubocop', '0.47.1', require: false
And add simple default-like rubocop configuration (run this in your project folder):
curl https://gist.githubusercontent.com/JerryGreen/cab79e62f4d8e08eabc19cc8a2776046/raw/rubocop.yml > .rubocop.yml
TODO: maybe use this https://github.com/toshimaru/rubocop-rails ?
- Minitest is the main thing here. Lets you writing rails tests.
- FactoryGirl is your real friend helping you creating objects. Read this guide.
- SimpleCov is just 2 lines in
test_helper.rb
that generates coverage statistics for your project. - Minitest::Reporters is just another 2 lines in
test_helper.rb
that makes output of test runs much prettier.
Minitest already is a part of Rails so just add this:
group :development, :test do
gem 'factory_girl_rails', '4.8.0'
end
group :test do
gem 'minitest-reporters', '1.1.14'
gem 'simplecov', '0.14.1', require: false
end
And expand your test_helper.rb
to get it all work:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'simplecov'
SimpleCov.start 'rails'
require "minitest/reporters"
Minitest::Reporters.use!
require 'rails/test_help'
module ActiveSupport
class TestCase
include FactoryGirl::Syntax::Methods
end
end
I highly recommend to change default strategy of FactoryGirl to build
strategy, so add this lines to end of test.rb
and development.rb
environments too:
module FactoryGirl
class Factory
def default_strategy
@options[:default_strategy] || :build
end
end
end
P.S. I recommend writing controller tests as they are the most helpful.
Run this in your project folder:
curl https://gist.githubusercontent.com/JerryGreen/cab79e62f4d8e08eabc19cc8a2776046/raw/pre-commit.sh > .pre-commit.sh
curl -O https://gist.githubusercontent.com/JerryGreen/cab79e62f4d8e08eabc19cc8a2776046/raw/install-pre-commit.sh
chmod +x .pre-commit.sh
chmod +x install-pre-commit.sh
./install-pre-commit.sh
Now you can commit your changes. And after:
You should also add this command to your readme
file
./install-pre-commit.sh
Just copy&paste this list so they know how to use it right:
- http://www.rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md
- http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers
- Run
open coverage/index.html
to see coverage (this updates on running tests)
Existing .pre-commit.sh
should be enough but feel free to change this file, if you want to improve/change the automate process. Your teammates don't need to do somethings else as they have a symlink to this file.