rails / sprockets

Rack-based asset packaging system
MIT License
951 stars 789 forks source link

Need two assets compiled in rails test environment, but not compiled in rails production. #666

Open mileslane opened 4 years ago

mileslane commented 4 years ago

Expected behavior

With sprockets 4.0, there needs to be a way to differentiate between assets that need to be loaded in distinct rails environments. May there is a way to do this, but I haven't found it yet.

spec.js and spec.css are required for rspec to run automated tests against our application. However, these files are not seen by sprockets 4.0 when I try to deploy on AWS using OpsWorks.

Actual behavior

If I put those two files into the manifest.js file, the deployment breaks. If I leave those two files out of the manifest.js, my rspec tests will not run.

Tell us what happens instead

When running rspec without the two files in the manifest.js:

   Failure/Error: = stylesheet_link_tag 'spec', media: 'all' if Rails.env.test?
   ActionView::Template::Error:
     Asset `spec.css` was not declared to be precompiled in production.
     Declare links to your assets in `app/assets/config/manifest.js`.

When deploying on OpsWorks with the two files in manifest.js:

rake aborted! Sprockets::FileNotFound: couldn't find file 'spec.js'

System configuration

Example App (Reproduction) - THIS IS IMPORTANT YOUR ISSUE LIKELY WILL NOT BE RESOLVED WITHOUT THIS

Please provide an example app

I won't be able to set up an OpsWorks deployment on codetriage.com. The problem is simple. How can I have assets compiled in when needed in development and test, and not be compiled for production.

TomasBarry commented 4 years ago

@mileslane, did you manage to get anywhere with this? I am coming across the same issue.