I wonder between method and let definition inside rspec describe block? Why should I use let instead def?
let(:create_user) { post :create }
Vs
def create_user
post :create
end
Both ways seems to work the same inside the test:
expect { create_user }.to change { User.count }.by(1)
Not sure if it is the only difference, but let memoizes it's value. So it would be closer to:
def create_user
@_create_user ||= post :create
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With