Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ahastudio/534eb419a8deb5020a22 to your computer and use it in GitHub Desktop.
Save ahastudio/534eb419a8deb5020a22 to your computer and use it in GitHub Desktop.

Guard 사용하기

https://github.com/guard/guard

몇 가지 규칙에 따라 자동으로 뭔가를 해주는 프로그램.

일단 브랜치를 하나 만들고 작업 시작.

$ git fetch origin
$ git checkout -b support/guard origin/master

자동으로 테스트 실행

https://github.com/guard/guard-minitest

$ vi Gemfile

development 그룹을 찾아서 rubocop 관련 Gem 추가.

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 3.0'
  # Spring speeds up development by keeping your application
  # running in the background. Read more: https://github.com/rails/spring
  gem 'spring'

  gem 'guard'
  gem 'guard-minitest'
end
$ bundle
$ guard init minitest
$ vi Guardfile

아직 Rails 5.0.0.beta1을 지원하지 않기 때문에 Rails 4 섹션의 주석을 전부 풀어준다.

$ guard

테스트 파일이나 구현 파일을 고칠 때마다 테스트가 자동으로 실행됨.

> 프롬프트에서 그냥 엔터 치면 모든 테스트가 다 실행된다. exit를 입력하면 종료.

자동으로 코딩 표준 검사

https://github.com/guard/guard-rubocop

$ vi Gemfile

development 그룹을 찾아서 Gem 추가.

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 3.0'
  # Spring speeds up development by keeping your application
  # running in the background. Read more: https://github.com/rails/spring
  gem 'spring'

  gem 'guard'
  gem 'guard-minitest'
  gem 'guard-rubocop'
end
$ bundle
$ guard init rubocop
$ guard

코드가 바뀔 때마다 코딩 표준 검사.

Commit & Push & Pull Request

$ git add .
$ git commit
$ git push origin support/guard

Pull Rquest & Review 요청!

Travis CI 사용하기

https://travis-ci.org/

https://travis-ci.org/profile 에서 저장소 Sync 후 Switch on!

https://github.com/ahastudio/woowahan-api-demo -> https://travis-ci.org/ahastudio/woowahan-api-demo

$ git fetch origin
$ git checkout -b support/travis-ci origin/master
$ vi .travis.yml
language: ruby
rvm:
  - 2.3.0
script:
  - bundle exec rubocop
  - bundle exec rake db:migrate RAILS_ENV=test
  - bundle exec rake test

CI엔 RuboCop이 설치되지 않아 빌드가 실패한다.

$ vi Gemfile
group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 3.0'
  # Spring speeds up development by keeping your application
  # running in the background. Read more: https://github.com/rails/spring
  gem 'spring'

  gem 'rubocop', require: false
end

만약 guard-rubocop이 이미 추가된 상태라면, 이 작업은 불필요하다.

CI에선 vendor 디렉터리를 활용하기 때문에, RuboCop이 vendor를 검사하지 않게 해야 한다.

$ vi .rubocop.yml
Documentation:
  Enabled: false

AllCops:
  Exclude:
    - 'Gemfile'
    - 'Rakefile'
    - 'Guardfile'
    - 'config.ru'
    - 'bin/**/*'
    - 'db/**/*'
    - 'config/**/*'
    - 'vendor/**/*'
$ git add .
$ git commit
$ git push origin support/travis-ci

Pull Rquest & Review 요청!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment