RSpec request spec fails when running in group/file/suite
But the request spec does NOT fail when an individual test is run.
TL;DR
Remove config.include RSPec::Rails::ViewRendering
from your rspec configuration.
Lately I’ve been working on a ruby codebase that runs since at least 2009, which entitles it to the term legacy.
Needless to say, this application was developed as Ruby on Rails was developed so a lot of the
RoR framework stuff is implemented in-house since it was used before Rails added first-party
support (e.g., enum
model attributes). To make my life easier as I get with the day-to-day
stuff I follow a TDD workflow because:
- I don’t know the whole codebase
- I don’t wanna know the whole codebase
- I don’t wanna understand the codebase via production errors
This application, thank the developers before me, has an extensive test suite which includes unit tests (model & business logic tests) and integration tests (selenium/cucumber) but, as fortune would have it, I’m temporarily a solo developer and, as I’m not proficient using Selenium (and it really slows down CI runtime), I try to stick to rspec.
Anyway, I had to update an existing data flow to consider an additional parameter that would create an extra database record as a result under arbitrary conditions so, naturally, I looked for the existing tests and found out there were only a subset of tests written on cucumber.
I wrote me a request spec to test in-between classes and save me some time and, lo and behold, my tests passed when run individually but failed when the whole spec/file was run.
After a couple of days ducking around and finding no answer, I turned to Google for Rails 5 now-sunken knowledge and found this StackOverflow entry detailing my situation which, thank the gods, unblocked me with a single line code change after 3 days of scratching my head with frustration.
The error itself was:
And the app had this in its rspec configuration:
After removing this view rendering configuration mixin, my request
specs passed when running
with the whole suite and not just when running individually.
Conclusion
- ChatGPT is NOT ready to solve my day-to-day problems (please generate documentation for my codebase!)
- Sadly, DuckDuckGo hasn’t phased out
AdStoreGoogle - Big ol’ G is still a necessary evil