DEV: Fix flaky test in spec/lib/svg_sprite/svg_sprite_spec.rb (#35673)

We should clean up at the end of each test instead of at the start to
ensure that there aren't any side effects.

In this particular case, `SvgSprite.expire_cache` calls
`DistributedCache#clear` but the cache is only cleared at the end of a
transaction. If we clear the cache in a `before` hook, the cache isn't
actually cleared until the existing transaction for the test has ended.
This commit is contained in:
Alan Guo Xiang Tan
2025-10-29 13:00:21 +08:00
committed by GitHub
parent 7d19dfd291
commit 80bcbd274e
+3 -2
View File
@@ -3,10 +3,11 @@
RSpec.describe SvgSprite do
fab!(:theme)
before do
before { allow(Rails.env).to receive(:test?).and_return(false) }
after do
SvgSprite.clear_plugin_svg_sprite_cache!
SvgSprite.expire_cache
allow(Rails.env).to receive(:test?).and_return(false)
end
it "can generate a bundle" do