简体   繁体   中英

Can I modify Capybara page bodies before the browser receives it?

I have a Rails application with Capybara for feature specs. I have some code that results in a url like this /Users/brandoncc/dev/app/public/uploads/... . This is a special circumstance in the test environment. I need to modify the response body before the browser gets it. Is that possible? I need to cut off the /Users/brandoncc/dev/app/public from image urls.

You have a number of options here - the top 3 are probably

  1. A programmable proxy like puffing-billy
  2. Write a rack middleware class and specify to use it in your config/environments/test.rb via config.middleware.use=
  3. Write a rack app to wrap the app under test which modifies the responses before returning them and assign that to Capybara.app

Any of those approaches should do what you want, but you may be better off just figuring out why the code is putting full paths in the URLs and fix it to use something like the rails asset helpers instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM