2

My problem is that I followed this tutorial to try to load the assets in test environment when debugging with Capybara method save_and_open_page, but I get the following error:

No route matches [GET] "/public/assets/application-22cc3ed14274a8cdae6670ce999946a627b5fd03c71819fbe4453118dca5ff40.css">

I added the following parameters in environments/test.rb to try to make them work but I still getting this error.

config.assets.digest = true
config.assets.prefix = '../public/assets/'
config.assets.quiet = true
config.assets.precompile += %w( *.js *.css )
config.public_file_server.enabled = true

Thanks for the help!

Rodrigo Chaves
  • 1,094
  • 8
  • 23

2 Answers2

1

If you've precompiled your assets in the test environment, then rather than following that article (which is 3 years old and out of date), you should be able to set Capybara.asset_host to whatever the address of your dev or test instance is - something like

Capybara.asset_host = 'http://127.0.0.1:3000'

This will add that into a base tag in the document when saving and opening the page.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • I tried this and also didn't help. I tried this config with `config.assets.prefix = ""` but I tested commenting `Capybara.asset_host = 'http://127.0.0.1:3000'` and the assets keep working. Do you know why? – Rodrigo Chaves Jun 24 '17 at 17:05
  • Huh? I don't understand you're question -- what do you mean the assets keep working? I thought the whole issue was they weren't working? If you mean the assets in the normal test run keep working, that's because `Capybara.asset_host` only affects pages during saving -- Did it add a `base` tag to the document it saved and opened? If so, did you have your dev instance running when the document was opened? Had you precompiled your test assets? – Thomas Walpole Jun 24 '17 at 17:09
  • I'm sorry by the confusing! I'll rephrase myself. I tried with the exact configs as the question and with `Capybara.asset_host = 'http://127.0.0.1:3000'` and didn't work. – Rodrigo Chaves Jun 24 '17 at 21:02
  • @RodrigoChaves But did it add the `base` tag to the document it saved and opened? You shouldn't need to make any of the changes from the tutorial, just set `asset_host`, precompile your assets for the test env before running your test, and leave your dev env running (if specifying port 3000 in asset_host, assuming your dev env is running on 3000) – Thomas Walpole Jun 24 '17 at 22:32
0

I changed this confid in test.rb and worked:

config.assets.prefix = '../public/assets/'

to

config.assets.prefix = ''
Rodrigo Chaves
  • 1,094
  • 8
  • 23