éãã¨ããã使ãåãæ¹ãããããªã
ï¼è¿½è¨ã¢ãªï¼
letã¯ä½¿ãããã¿ã¤ãã³ã°ã§å¦çããããlet!ã¯æ¯åå¦çããããã
ã¦ã£ãããletã¯ä¸ååæåãããã使ãã¾ãããããã ã¨æã£ã¦ãããã©ãå¼ã³åºãããã¨ãã¯æ¯ååæåããããã ã
describe 'let_test' do let(:sample_1){ puts "****let****"; 'sample1'} let!(:sample_2){ puts "****let!****"; 'sample2'} before do puts "before---" end after do puts "after----" end it { sample_1.should eq 'sample1'} it { sample_1.should eq 'sample1'} it { sample_2.should eq 'sample2'} it { sample_2.should eq 'sample2'} end
å®è¡çµæã¯ãããªæãã
%rspec --format doc let_spec.rb let_test ****let!**** before--- ****let**** after---- should eq "sample1" ****let!**** before--- ****let**** after---- should eq "sample1" ****let!**** before--- after---- should eq "sample2" ****let!**** before--- after---- should eq "sample2" Finished in 0.00204 seconds 4 examples, 0 failures
ã¡ãã£ã¨è¦ã«ãããã©ãletåã³let!ã®{}ãå¼ã°ããã¿ã¤ãã³ã°ã確èªãã¦ãããletã¯é
延è©ä¾¡ãããã¿ãããªã®ãèªãã ãã¨ããã£ãã®ã§ãä¸åå¼ã°ããããã£ãã·ã¥ãããï¼ã¤ã¾ããsample_1ãäºåç®ã«å¼ã°ããã¨ã㯠****let**** ãå¼ã°ããªãï¼ã¨æã£ã¦ãããããã§ã¯ãªãã£ããã¨ããã¨ãã©ã¡ãã«ãã使ãã¨ãã«ã¯åæåãããã®ã ãã使ãåããå¿
è¦ãããã®ã ãããâ¦â¦ã¨ããã¨ããã§ããããããªããªã£ã¦é ããããã¼ãããã«ãªã£ãã
The RSpec Book (Professional Ruby Series)
- ä½è : David Chelimsky,Dave Astels,Zach Dennis,è§è°·ã信太é,è±ç°ãç¥å¸,æ ªå¼ä¼ç¤¾ã¯ã¤ã¼ã
- åºç社/ã¡ã¼ã«ã¼: ç¿æ³³ç¤¾
- çºå£²æ¥: 2012/02/22
- ã¡ãã£ã¢: 大åæ¬
- è³¼å ¥: 7人 ã¯ãªãã¯: 141å
- ãã®ååãå«ãããã° (16件) ãè¦ã
ããã«ä½ãæ¸ãã¦ãããããªãã ãã©ãã¡ãã£ã¨æå ã«ãªã*1ã®ã§ãã¡ã¢ãã¦ãæ¸ãã¦ãããããããã°èè ãæãã¦ããããããããªããã!!ï¼è©³ããæ¹ããããã¦ãã ããï¼ï¼ï¼
æãã¦ããã£ã
letã¯ãã£ãã·ã¥ããããã ãã©ãããã®ç¯å²ã¯beforeãitãafterã®ç¯å²ã§ä¸åããåæåãããªãã¨ããæå³ã ãããªãã¤ã¾ãä¸è¨ã®ã³ã¼ãã§ã¯ããã¾ãæå³ããªãã£ãã®ã ã£ã!
*1:ä¼ç¤¾ã«ããã£ã±ãªãâ¦â¦