Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
6
Help us understand the problem. What is going on with this article?
@nagane

railsプロジェクトを始めるときの流れ

More than 5 years have passed since last update.

新しくプロジェクトをつくろうとした時に思った事

newとか必要なgemとか忘れてて最小構成を調べ直した・・・

ということで備忘録としてまとめておきます

やりたいこと

  • DBはmysql
  • testはrspec
  • テストを便利にするツールは最初から組み込む
  • travis ciが動くようにする

プロジェクトを作成する

testはrspecで行うためにtest::unitを組み込まない

rails new srvadmin --skip-test-unit -d mysql

実行ログは下記


      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/views/layouts/application.html.erb
      create  app/assets/images/.keep
      create  app/mailers/.keep
      create  app/models/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/secrets.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/robots.txt
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep
         run  bundle install


Your user account isn't allowed to install to the system Rubygems.
You can cancel this installation and run:

    bundle install --path vendor/bundle

to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to Rubygems using sudo.

Password:
Fetching gem metadata from https://rubygems.org/...........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Installing rake 10.3.2
Using i18n 0.6.9
Using json 1.8.1
Installing minitest 5.3.5
Installing thread_safe 0.3.4
Installing tzinfo 1.2.1
Using activesupport 4.1.0
Using builder 3.2.2
Using erubis 2.7.0
Using actionview 4.1.0
Using rack 1.5.2
Using rack-test 0.6.2
Using actionpack 4.1.0
Using mime-types 1.25.1
Installing polyglot 0.3.5
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 4.1.0
Using activemodel 4.1.0
Using arel 5.0.1.20140414130214
Using activerecord 4.1.0
Using bundler 1.6.2
Using coffee-script-source 1.7.0
Installing execjs 2.2.0
Using coffee-script 2.2.0
Using thor 0.19.1
Using railties 4.1.0
Using coffee-rails 4.0.1
Using hike 1.2.3
Installing multi_json 1.10.1
Installing jbuilder 2.1.1
Using jquery-rails 3.1.0
Installing mysql2 0.3.16
Using tilt 1.4.1
Using sprockets 2.11.0
Using sprockets-rails 2.1.3
Using rails 4.1.0
Using rdoc 4.1.1
Installing sass 3.2.19
Installing sass-rails 4.0.3
Using sdoc 0.4.0
Installing spring 1.1.3
Installing turbolinks 2.2.2
Installing uglifier 2.5.1
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
         run  bundle exec spring binstub --all
* bin/rake: spring inserted
* bin/rails: spring inserted

新しいアプリが作成されました。

gemに使うプラグインをインストールする

rspec等のテスト系で使うやつを予めインストールします
gemfileに以下を追加


group :development, :test do
  gem 'rspec-rails'
  gem 'capybara'
  gem 'spork-rails'
  gem 'guard-spork'
  gem 'childprocess' 
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
end

プラグイン追加

bundle install

Rspec準備

rails generate rspec:install

      create  .rspec
      create  spec
      create  spec/spec_helper.rb
      create  spec/rails_helper.rb

Travis Ci準備

アプリのhomeディレクトリに.travis.ymlを準備する

travis.yml

language: ruby
rvm:
  - 2.1.0
gemfile:
  - Gemfile
env:
  - DB=mysql
before_script:
  - "cp config/database_travis.yml config/database.yml"
script:
  - bundle install --standalone --clean
  - RAILS_ENV=test bundle exec rake --trace db:create
  - RAILS_ENV=test bundle exec rake --trace db:migrate
  - bundle exec rake db:test:prepare
  - bundle exec rspec spec/

travisciが動いた時用のdatabase_travis.ymlも準備する

conifg/database_travis.yml

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password:
  host: localhost

development:
  <<: *default
  database: srvadmin_development

test:$
  <<: *default
  database: srvadmin_test

production:
  <<: *default
  database: srvadmin_production
  username: srvadmin
  password: <%= ENV['SRVADMIN_DATABASE_PASSWORD'] %>

database.ymlはデフォルト
 
 
guardやsporkの設定等もありますが
とりあえずここまでがアプリ初期設定とします。

この変は1回目のテストをする時にまとめるか、随時追記する。

6
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
nagane
infra engineer Lv9 ruby/bash/golang

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
6
Help us understand the problem. What is going on with this article?