I have been told that it makes sense to use let!()
instead of before(:each)
block. However, I can't see much logic in doing that. Does it actually make any sense to make something like in the example below:
context 'my super context' do
let!(:something) do
Model.create(subject: "Hello", body: "World")
end
it '...' do
# We never call something
# All we want is just to evaluate and create the record
end
end
Keep in mind that you won't call something
anywhere in the example at all. Technically I don't see much difference between that and this, unless it's actually more strict and easy to understand without documentation just like plain English:
context 'my super context' do
before(:each) do
Model.create(subject: "Hello", body: "World")
end
it '...' do
# We never call something
# All we want is just evaluate and create the record
end
end
Could someone help me to understand the idea behind the rule I was given?
I can understand why you would use let
instead of before(:all)
and before(:each)
with the variable inside. But here it just feels like they just blindly follow the phrase "use a let helper instead of a before block" found somewhere in the blog post.
Thank you very much!