Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Set up Ruby project

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for nacyot nacyot
September 02, 2015

Set up Ruby project

루비 프로젝트 준비하기(Set up Ruby project)
RORLab 77번째 모임 (2014. 12. 23.)
by nacyot http://blog.nacyot.com

루비는 프로그래밍 언어이다. 프로그래밍 언어에서 제공하는 핵심적인 기능 중 하나는 코드 조각들을 적절한 단위로 모아서 정리하고, 이를 다시 사용할 수 있도록 도와준다는 점이다. 이러한 기능을 통해 프로그래머는 추상화 계층을 적절히 제어할 수 있으며, 같은 기능을 필요로 하는 사람들과 라이브러리를 공유할 수 있다.

이 발표에서는 루비에서 (관습적인) 기본적인 프로젝트 구조를 만드는 법에 대해서 살펴본다.

Avatar for nacyot

nacyot

September 02, 2015
Tweet

More Decks by nacyot

Other Decks in Programming

Transcript

  1. RORLab 77ߣ૩ ݽ੐ 2014. 12. 23. 2015. 8. 31. update

    Set up Ruby Project © nacyot 2015 - 2
  2. ೐۽ં౟ ౟ܻ $ tree -d -L 2 . ├── app

    │ ├── assets │ ├── controllers │ ├── models │ └── views ├── bin ├── config │ ├── environments │ ├── initializers ├── db │ └── migrate ├── lib ├── log ├── public ├── spec │ ├── controllers │ ├── models └── tmp Set up Ruby Project © nacyot 2015 - 7
  3. ೐۽ં౟ ౟ܻ(೧ࢸ ୎ࠗ) $ tree -d -L 2 . ├──

    app # য೒ܻா੉࣌ ௏٘ │ ├── assets # ীࣇ │ ├── controllers # ஶ౟܀۞ │ ├── models # ݽ؛ │ └── views # ࠭ ├── bin # प೯ ౵ੌ ├── config # ࢸ੿ │ ├── environments # ജ҃߹ ࢸ੿ │ ├── initializers # য೒ܻா੉࣌ ୡӝച झ௼݀౟ ├── db # ؘ੉ఠ߬੉झ ҙ۲ │ └── migrate # ݃੉Ӓۨ੉࣌ ├── lib # ۄ੉࠳۞ܻ ├── log # ۽Ӓ ├── public # ੿੸ ౵ੌ ├── spec # పझ౟ │ ├── controllers # ஶ౟܀۞ పझ౟ │ ├── models # ݽ؛ పझ౟ └── tmp # ੐द ౵ੌ Set up Ruby Project © nacyot 2015 - 8
  4. ೐۽ં౟ ౟ܻ $ tree -d -L 2 . ├── foo/

    ├── bar/ ├── my_library/ └── awesome.rb Set up Ruby Project © nacyot 2015 - 15
  5. ೞ૑݅, ҙण੸ੋ ҳઑо ઓ੤ . ȍȇȇ lib ȍȇȇ test ȍȇȇ

    Gemfile ȍȇȇ Rakefile Ȍȇȇ README.md Set up Ruby Project © nacyot 2015 - 17
  6. ੌױ READMEࠗఠ ٜ݅ӝ $ touch README.md ੍যࠁӝ : Readme Driven

    Development Set up Ruby Project © nacyot 2015 - 19
  7. ۄ੉࠳۞ܻ ౵ੌ ٜ݅ӝ $ touch lib/my_awesome_ruby_project.rb # lib/my_awesome_ruby_project.rb class MyAwesomeRubyProject

    end require './lib/my_awesome_ruby_project/awesome_cat' Set up Ruby Project © nacyot 2015 - 21
  8. ۄ੉࠳۞ܻ ࢎਊೞӝ [1] pry(main)> require('./lib/my_awesome_ruby_project') => true [2] pry(main)> my_cat

    = MyAwesomeRubyProject::AwesomeCat.new => #<MyAwesomeRubyProject::AwesomeCat:0x007f96f29e6ef8> [3] pry(main)> my_cat.mew => "Nyaa~" Set up Ruby Project © nacyot 2015 - 23
  9. ׮द ࢓ಝࠁӝ . ├── lib │ ├── my_awesome_ruby_project │ │

    └── awesome_cat.rb │ └── my_awesome_ruby_project.rb └── README.md Set up Ruby Project © nacyot 2015 - 24
  10. RSpec $ bundle exec rspec /Users/... in `block in replace_gem':

    rspec-core is not part of the bundle. Add it to Gemfile. (Gem::LoadError) from /Users/...:22:in `<main>' Set up Ruby Project © nacyot 2015 - 26
  11. Gemfile ࢤࢿೞӝ $ bundle init Writing new Gemfile to /.../my_awesome_ruby_project/Gemfile

    # Gemfile source "https://rubygems.org" Set up Ruby Project © nacyot 2015 - 30
  12. bundle install $ bundle install Fetching gem metadata from https://rubygems.org/.........

    Resolving dependencies... Using diff-lcs 1.2.5 Using rspec-support 3.1.2 Using rspec-core 3.1.7 Using rspec-expectations 3.1.2 Using rspec-mocks 3.1.3 Installing rspec 3.1.0 Using bundler 1.7.3 Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. Set up Ruby Project © nacyot 2015 - 32
  13. పझ౟ प೯ೞӝ $ bundle exec rspec No examples found. Finished

    in 0.00017 seconds (files took 0.04335 seconds to load) 0 examples, 0 failures Set up Ruby Project © nacyot 2015 - 33
  14. పझ౟ ળ࠺ೞӝ $ mkdir -p spec/my_awesome_ruby_project/ $ touch spec/spec_helper.rb $

    touch spec/my_awesome_ruby_project/awesome_cat_spec.rb # spec/spec_helper.rb require './lib/my_awesome_ruby_project' Set up Ruby Project © nacyot 2015 - 35
  15. పझ౟ प೯ೞӝ $ bunedl exec rspec Pending: MyAwesomeRubyProject::AwesomeCat My first

    awesome test # Not yet implemented # ./spec/my_awesome_ruby_project/awesome_cat_spec.rb:4 Finished in 0.00029 seconds (files took 0.10246 seconds to load) 1 example, 0 failures, 1 pending Set up Ruby Project © nacyot 2015 - 37
  16. ୐ (૓૞) పझ౟ ੘ࢿೞӝ require './spec/spec_helper' describe MyAwesomeRubyProject::AwesomeCat do it

    "My first awesome test" do expect(MyAwesomeRubyProject::AwesomeCat.new.mew).to eq "Nyaa~" end end Set up Ruby Project © nacyot 2015 - 38
  17. ׮द, పझ౟ प೯ೞӝ $ rspec --color --format doc MyAwesomeRubyProject::AwesomeCat My

    first awesome test Finished in 0.00086 seconds (files took 0.09874 seconds to load) 1 example, 0 failures Set up Ruby Project © nacyot 2015 - 39
  18. ৈӝө૑ ҳઑ . ├── lib │ ├── my_awesome_ruby_project │ │

    └── awesome_cat.rb │ └── my_awesome_ruby_project.rb ├── spec │ ├── my_awesome_ruby_project │ │ └── awesome_cat_spec.rb │ └── spec_helper.rb ├── .rspec ├── Gemfile ├── Gemfile.lock └── README.md Set up Ruby Project © nacyot 2015 - 41
  19. Guard Guard is a command line tool to easily handle

    events on file system modifications. Set up Ruby Project © nacyot 2015 - 43
  20. bundlerী Guard ୶оೞӝ # Gemfile source "https://rubygems.org" gem "rspec" gem

    "guard" gem "guard-rspec" Set up Ruby Project © nacyot 2015 - 44
  21. Guardfile ࢤࢿೞӝ $ bundl exec guard init 20:14:38 - INFO

    - Writing new Guardfile to /Users/.../Guardfile 20:14:38 - INFO - rspec guard added to Guardfile, feel free to edit it Set up Ruby Project © nacyot 2015 - 46
  22. Guardfile ૒੽ ٜ݅ӝ # Guardfile guard :rspec, cmd: 'bundle exec

    rspec' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } end Set up Ruby Project © nacyot 2015 - 47
  23. ୭ઙ ҳઑ . ├── lib │ ├── my_awesome_ruby_project │ │

    └── awesome_cat.rb │ └── my_awesome_ruby_project.rb ├── spec │ ├── my_awesome_ruby_project │ │ └── awesome_cat_spec.rb │ └── spec_helper.rb ├── .rspec ├── Gemfile ├── Gemfile.lock ├── Guardfile └── README.md Set up Ruby Project © nacyot 2015 - 49
  24. ୭ઙ ҳઑ(೧ࢸ) . ├── lib # ۄ੉࠳۞ܻ ௏٘ │ ├──

    my_awesome_ruby_project │ │ └── awesome_cat.rb │ └── my_awesome_ruby_project.rb ├── spec # పझ౟ │ ├── my_awesome_ruby_project │ │ └── awesome_cat_spec.rb │ └── spec_helper.rb # పझ౟ ҙ۲ ࢸ੿ ౵ੌ ├── .rspec # rspec ࢸ੿ ౵ੌ ├── Gemfile # ੄ઓࢿ ࢶ঱ ౵ੌ ├── Gemfile.lock # ੄ઓࢿ Ҋ੿ ౵ੌ ├── Guardfile # Guard ࢸ੿ ౵ੌ └── README.md # README(೐۽ં౟ ࢸ੿) Set up Ruby Project © nacyot 2015 - 50
  25. ੌ߈੸ੋ ܖ࠺ ೐۽ં౟ ҳઑ . ├── bin/ # प೯ ౵ੌ

    ├── lib/ # ۄ੉࠳۞ܻ ௏٘ ├── spec/ # పझ౟ ௏٘ ├── tmp/ # ੐द ౵ੌ ├── Gemfile # Bundler ಁః૑ ࢶ঱ ౵ੌ ├── Guardfile ├── Rakefile # Rake Task ੿੄ ౵ੌ ├── LICENSE.txt # ۄ੉ࣃझ ౵ੌ └── README.md # README ౵ੌ Set up Ruby Project © nacyot 2015 - 51