I tried to look around to see if it's indeed documented that let(:X) can be used within before(:each) safely with the cache value cleared before each "before(:each)" execution, that means that on the before(:each) execution the cached value from the previous example isn't in use anymore but new on is generated on the first call to the defined let method (see the example below).
From before(:each)/before(:example) documentation in relishapp-
https://relishapp.com/rspec/rspec-core/v/3-5/docs/hooks/before-and-after-hooks
"Use before and after hooks to execute arbitrary code before and/or after the body of an example is run.."
The let() documentation is relishapp: "Use let to define a memoized helper method. The value will be cached across multiple calls in the same example but not across examples."
https://relishapp.com/rspec/rspec-core/v/3-5/docs/helper-methods/let-and-let
So is it gauranteed that on every before(:each)/before(:example) execution we'll get the "fresh" value genereated by the let and not a chached one(that means according to the documentation, that the before(:each)/before(:example) block is considered as part of the example)? I know it makes sense, but I don't see it somewhere documented - can someone provide a link to a documentation in which it's written?
Example code:
describe 'SOMETHING' do
let(:first) { Object.new }
before do
stub(first).foo? { true }
end
it 'test1' do
# will first.foo? always returns true here?
#Some test work...
end
it 'test2' do
# will first.foo? always returns true here?
# any chance the stubbing in the before occurs
# on the instance from the previous test before
# the value is cleared from the cache?
#Test2...
end
end