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.


The Dark Knight Rises meme representing Google as a necessary evil.
Google still has a big knowledge base that other search engines don't.

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:

  1. I don’t know the whole codebase
  2. I don’t wanna know the whole codebase
  3. 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:

ActionController::UnknownFormat:
  MyController#show is missing a template for this request format and variant.

  request.formats: ["text/html"]
  request.variant: []

And the app had this in its rspec configuration:

# spec/rails_helper.rb
RSpec.configure do |config|
  ...

  config.include RSPec::Rails::ViewRendering
end

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 AdStore Google
  • Big ol’ G is still a necessary evil