Making Rails tests aware of Rack middleware outside Rails's internal chain

后端 未结 2 1144
旧时难觅i
旧时难觅i 2021-02-02 14:37

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

2条回答
  •  忘掉有多难
    2021-02-02 15:30

    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
    

提交回复
热议问题