Context: an application uses a piece of Rack middleware that must be setup in config.ru, rather than Rails\'s internal Middleware chain. This i
I think the problem is that ActionDispatch::IntegrationTest uses your Rails.application as its Rack app for the test.
So, if you can wrap that Rack::Rewrite rule into some Rack middleware, you should be able to override the Rack app you're testing in your test with:
ActionDispatch::IntegrationTest.app = MyRewriteMiddleware