Rails fragment cache testing with RSpec

前端 未结 3 479
生来不讨喜
生来不讨喜 2021-02-04 15:22

I feel like this is a not-so-much documented topic, at least I\'ve had a lot of trouble finding our about the best practices here.

I\'m fragment caching in the view usin

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 15:45

    Let me first say that in this answer, you may get more sympathy then fact. I've been struggling with these same issues. While I was able to get reproducible results for a particular test, I found that the results varied according to whether or not I ran one versus multiple specs, and within or without spork. Sigh.

    In the end, I found that 99.9% of my issues disappeared if I simply enabled caching in my test.rb file. That might sound odd, but after some thought it was "correct" for my application. The great majority of my tests are not at the view/request layer, and for the few that are, doesn't it make sense to test under the same configurations that the user views?

    While I was wrestling with this, I wrote a blog post that contains some useful test helpers for testing caching. You might find it useful.

提交回复
热议问题