Open key88sf opened 3 years ago
Ideally we wouldn't be doing this for request specs, but you could hack around this problem with rspec by adding to your spec_helper.rb
:
config.before do
RequestStore.clear!
end
@KelseyDH Yeah that is what we ended up doing for now.
I had a similar issue, and found @KelseyDH's suggestion did not solve my problem because my Rspec tests were expecting data changes during the test, and RequestStore was dutifully making the test code act as if it were all in one request, so I could not see the data change. As a solution, I found this mock useful to allow a specific test to bypass the effects of a RequestStore.fetch
. NOT recommended for controller or request specs!
allow(RequestStore).to receive(:fetch) { |&block| block.call }
Rails 5, Rspec 3.10.0
It looks like RequestStore is not being cleared in-between rspec unit tests when used in something like a helper spec, or any non-controller unit tests.
Do we need to manually clear it for these, or should this be automatic in any Rails rspec test?