新規プロジェクト作成しrspec導入、リンター導入まで
新規プロジェクト作成手順
1.workspaceに移動
$rails new appname -d postgresql
これでDBにpostgresqlを使用する事を指定し、bundle installまですむ。
2.$git init
3.$bin/rails db:create
4.$bin/rails sでhello worldを確認
5.
gem 'slim-rails'
gem 'html2slim'
gem 'bootstrap'
をbundle install
6.$ bundle exec erb2slim app/views/layouts/ --deleteでerb形式のファイルを削除。
7.rm app/assets/stylesheets/application.cssと touch app/assets/stylesheets/application.scssを行い作ったファイルに@import "bootstrap";を記述
8.rspecのインストール
gem 'rspec-rails', '~> 3.6.0'
bundle installしbin/rails g rspec:install
9.--require spec_helper
--format documentationを.rspecに追記
10.bin/rspecを使用可能にし、テストの速度を上げる
gem 'spring-commands-rspec'
bundle installの後$bundle exec spring binstub rspec
11.application.rbに以下を記述し、generaterを使った時の挙動を記述
config.generators do |g|
g.test_framework :rspec,
fixtures: false,
view_specs: false,
helper_specs: false,
routing_specs: false
end
end
12.リンターの導入
gem 'rubocop'
gem 'rubocop-airbnb'
.rubocop
require:
- rubocop-airbnb
inherit_from:
- .rubocop_airbnb.yml
Rails:
Enabled: true
AllCops:
Exclude:
- db/*
- bin/*
LineLength:
Max: 150
.rubocop_airbnb.yml
require:
- rubocop-airbnb
の2つを作成し
$bundle exec rubocop --require rubocop-airbnb
を実行、その都度引っかかったところを修正。