タグ

2013年11月9日のブックマーク (1件)

  • すごいぞRSpec(letとlet!編) - @yohfee.blog!

    すでに前回のすごいぞRSpec(shared example group編) - ぷろぐらまねがで登場してるけどあらためてletを調べるよ。rspec-core(2.5.1)/features/helper_methods/let.featureを参考に。 let 要するにメモ化するわけで、同一サンプル内だと同じオブジェクトを使いまわせるのだな。違うサンプルでは改めて評価される。さらに遅延評価なので実際に評価されるのは最初にメソッドが呼ばれたときだ。 $count = 0 describe 'let' do let(:count) { $count += 1 } it 'memoizes the value' do count.should == 1 count.should == 1 end it 'is not cached across examples' do count.shou

    すごいぞRSpec(letとlet!編) - @yohfee.blog!
    kkabetani
    kkabetani 2013/11/09
    letが遅延評価なのに対してlet!はbefore each的に各サンプルの実行前に評価される。let!はbeforeと同じタイミングで上から順番に評価されるっぽい。