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

Set up Ruby project

Afeb8054efb8e03aab4ed7d90a52f11c?s=47 nacyot
September 02, 2015

Set up Ruby project

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

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

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

Afeb8054efb8e03aab4ed7d90a52f11c?s=128

nacyot

September 02, 2015
Tweet

Transcript

  1. Set up Ruby Project Set up Ruby Project © nacyot

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

    Set up Ruby Project © nacyot 2015 - 2
  3. Daekwon Kim SMARTSTUDY Software & System Engineer Set up Ruby

    Project © nacyot 2015 - 3
  4. Set up Ruby Project © nacyot 2015 - 4

  5. Ruby On Rails Set up Ruby Project © nacyot 2015

    - 5
  6. rails new $ rails new <PROJECT_NAME> Set up Ruby Project

    © nacyot 2015 - 6
  7. ೐۽ં౟ ౟ܻ $ 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
  8. ೐۽ં౟ ౟ܻ(೧ࢸ ୎ࠗ) $ 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
  9. झझ۽ ੗न੄ ਤ஖ܳ ঌҊ ੓਺ Set up Ruby Project ©

    nacyot 2015 - 9
  10. ۨੌझח ೐ۨ੐ਕ௼ Set up Ruby Project © nacyot 2015 -

    10
  11. ܖ࠺ Set up Ruby Project © nacyot 2015 - 11

  12. ۨੌझח ೐ۨ੐ਕ௼ Set up Ruby Project © nacyot 2015 -

    12
  13. ܖ࠺ب ೐ۨ੐ਕ௼? Set up Ruby Project © nacyot 2015 -

    13
  14. ruby new $ mkdir my_awesome_ruby_project Set up Ruby Project ©

    nacyot 2015 - 14
  15. ೐۽ં౟ ౟ܻ $ tree -d -L 2 . ├── foo/

    ├── bar/ ├── my_library/ └── awesome.rb Set up Ruby Project © nacyot 2015 - 15
  16. ੗ਬ! Set up Ruby Project © nacyot 2015 - 16

  17. ೞ૑݅, ҙण੸ੋ ҳઑо ઓ੤ . ȍȇȇ lib ȍȇȇ test ȍȇȇ

    Gemfile ȍȇȇ Rakefile Ȍȇȇ README.md Set up Ruby Project © nacyot 2015 - 17
  18. ૒੽ ٜ݅যࠁ੗! Set up Ruby Project © nacyot 2015 -

    18
  19. ੌױ READMEࠗఠ ٜ݅ӝ $ touch README.md ੍যࠁӝ : Readme Driven

    Development Set up Ruby Project © nacyot 2015 - 19
  20. lib/ ٣۩షܻ ٜ݅ӝ $ mkdir lib Set up Ruby Project

    © nacyot 2015 - 20
  21. ۄ੉࠳۞ܻ ౵ੌ ٜ݅ӝ $ 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
  22. ֎੐झಕ੉झ $ mkdir lib/my_awesome_ruby_project $ touch lib/my_awesome_ruby_project/awesome_cat.rb # lib/my_awesome_ruby_project_awesome_cat.rb class

    MyAwesomeRubyProject::AwesomeCat def mew "Nyaa~" end end Set up Ruby Project © nacyot 2015 - 22
  23. ۄ੉࠳۞ܻ ࢎਊೞӝ [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
  24. ׮द ࢓ಝࠁӝ . ├── lib │ ├── my_awesome_ruby_project │ │

    └── awesome_cat.rb │ └── my_awesome_ruby_project.rb └── README.md Set up Ruby Project © nacyot 2015 - 24
  25. Test ജ҃ ҳ୷ೞӝ Set up Ruby Project © nacyot 2015

    - 25
  26. 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
  27. Bundler ੄ઓࢿ ҙܻ بҳ Set up Ruby Project © nacyot

    2015 - 27
  28. ੄ઓࢿ ೐۽ં౟ীࢲ ࢎਊೞח ۄ੉࠳۞ܻ Set up Ruby Project © nacyot

    2015 - 28
  29. Gemfile ੄ઓࢿ ࢶ঱ ౵ੌ Set up Ruby Project © nacyot

    2015 - 29
  30. Gemfile ࢤࢿೞӝ $ bundle init Writing new Gemfile to /.../my_awesome_ruby_project/Gemfile

    # Gemfile source "https://rubygems.org" Set up Ruby Project © nacyot 2015 - 30
  31. Gemfileী rspec ୶оೞӝ source "https://rubygems.org" gem "rspec" Set up Ruby

    Project © nacyot 2015 - 31
  32. 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
  33. పझ౟ प೯ೞӝ $ 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
  34. No examples found Set up Ruby Project © nacyot 2015

    - 34
  35. పझ౟ ળ࠺ೞӝ $ 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
  36. ୐ (о૞) పझ౟ ੘ࢿೞӝ # spec/my_awesome_ruby_project/awesome_cat_spec.rb require './spec/spec_helper' describe MyAwesomeRubyProject::AwesomeCat

    do it "My first awesome test" end Set up Ruby Project © nacyot 2015 - 36
  37. పझ౟ प೯ೞӝ $ 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
  38. ୐ (૓૞) పझ౟ ੘ࢿೞӝ 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
  39. ׮द, పझ౟ प೯ೞӝ $ 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
  40. .rspec --color --format doc Set up Ruby Project © nacyot

    2015 - 40
  41. ৈӝө૑ ҳઑ . ├── 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
  42. ੸੺ೠ بҳܳ ഝਊೠ Test Driven Development Set up Ruby Project

    © nacyot 2015 - 42
  43. Guard Guard is a command line tool to easily handle

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

    "guard" gem "guard-rspec" Set up Ruby Project © nacyot 2015 - 44
  45. ੄ઓࢿ ࢸ஖ೞӝ $ bundle install Set up Ruby Project ©

    nacyot 2015 - 45
  46. 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
  47. 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
  48. Test Driven Demo Set up Ruby Project © nacyot 2015

    - 48
  49. ୭ઙ ҳઑ . ├── 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
  50. ୭ઙ ҳઑ(೧ࢸ) . ├── 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
  51. ੌ߈੸ੋ ܖ࠺ ೐۽ં౟ ҳઑ . ├── bin/ # प೯ ౵ੌ

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

    - 52