2

My team is using SitePrism for feature tests in a Rails 4 app, and we're currently restructuring our CSS assets in the project. One of the asset files includes a line that @imports from a subdirectory:

app/assets/stylesheets/lib/admin.scss.css:

   @import "base/base-admin";

and app/assets/stylesheets/lib/base/base-admin.scss in turn includes:

   @import "shared/reset";
   @import "shared/colors";
   @import "shared/breakpoints";
   @import "shared/grids";

This all works fine in development in the browser (I get no errors from requests to lib/admin.css, and I see the CSS rules are applied to the page correctly).

But when I run our feature tests, I get

Failure/Error: @page.load
ActionView::Template::Error:
  File to import not found or unreadable: base/base-admin.
  Load paths:
    /Users/duncanmalashock/ruby_projects/platform
    /Users/duncanmalashock/ruby_projects/platform/.bundle/gems/ruby/2.2.0/gems/bootstrap-sass-3.3.4.1/assets/stylesheets
 (in /Users/duncanmalashock/ruby_projects/platform/app/assets/stylesheets/lib/admin.scss.css)

However, none of the other assets are broken in the test environment. Why can't these be found?

Duncan Malashock
  • 776
  • 10
  • 32
  • Do you have anything assets related in `config/environments/test.rb`? – Chase Oct 28 '15 at 20:44
  • No, I tried adding `config.assets_prefix = "/#{Rails.env}/assets"` but didn't get any helpful results. – Duncan Malashock Oct 28 '15 at 20:46
  • Also, the tests pass when the import line is `@import "app/assets/stylesheets/lib/base/base-admin";`, but of course then the app can't load it in the browser. – Duncan Malashock Oct 28 '15 at 20:53
  • Tried adding `config.assets.paths << "#{Rails.root}/app/assets/stylesheets/lib"` in both `initializers/assets.rb` and `environments/test.rb` but the list of load paths didn't change. – Duncan Malashock Oct 28 '15 at 22:55
  • 1
    This turned out to be a naming error. The suffixes on my manifest were ".scss.css", so the Asset Pipeline was trying to @import a file in the wrong way (via CSS rather than SCSS). – Duncan Malashock Oct 29 '15 at 22:17
  • Ahh, I should have scrolled on the code box. :) You should post the fix on your question for future googlers. – Chase Oct 30 '15 at 03:27

1 Answers1

0

This turned out to be a naming error. The suffixes on my manifest were ".scss.css", instead of ".css.scss" (which would have been correct).

The Asset Pipeline starts with the last suffix, and tries to run a process that matches it, then repeats with the next suffix in.

So the Pipeline was trying to @import a file in the wrong way (there's an @import directive in CSS and also differently behaving one in SCSS), which was leading to unexpected behavior.

Duncan Malashock
  • 776
  • 10
  • 32