rspec中的let和let!區別

c3tc3tc3t發表於2017-11-17

文件

https://relishapp.com/rspec/rspec-core/v/2-5/docs/helper-methods/let-and-let

從上面文件中得出 

let

1 只會在一個example(一個it 程式碼塊)中呼叫一次,並不會在多個example中共享 ,

2 必須被顯示呼叫,不會被隱世提前呼叫

 

let!

1 每個example執行前被隱式自動呼叫

2 在其他example中返回已經呼叫的記憶體中的引用,不會重新呼叫 ,意味著在多個example中,後面的example可以使用前面呼叫過的版本

相關文章