タグ

ブックマーク / yohfee.hatenadiary.org (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!
  • 1