jasmine / jasmine-gem

Jasmine ruby gem
681 stars 275 forks source link

Asset errors running jasmine:ci with sprockets-rails v3.2.0 #275

Closed sos4nt closed 7 years ago

sos4nt commented 8 years ago

I'm getting asset errors when running bundle exec rake jasmine:ci after updating sprockets-rails to 3.2.0:

!! Unexpected error while processing request: The asset "image.png" is not present in the asset pipeline.

The aforementioned image is referenced in a scss file via:

background-image: image-url('image.png');

And it's working fine otherwise, i.e. outside jasmine:ci.

I've tried to debug the issue and apparently, sprockets-rails doesn't have proper config values. The above error is raised in lib/sprockets/rails/helper.rb#L82-L83:

message =  "The asset #{ path.inspect } is not present in the asset pipeline."
raise AssetNotFound, message unless unknown_asset_fallback

unknown_asset_fallback is nil, although the default value is true. I don't explicitly set the value otherwise and even if I do explicitly set it to true, the config value doesn't find its way into the code – it remains nil.

Further investigation shows that Sprockets::Rails::Helper is being included twice, once into ActionView::Base and once into an anonymous class from within jasmine-gem in lib/jasmine/config.rb#L68.

I'm not sure what's missing here. Maybe jasmine-gem has to run this callback:

ActiveSupport.on_load(:action_view) do
  include Sprockets::Rails::Helper

  # Copy relevant config to AV context
  self.debug_assets      = config.assets.debug
  self.digest_assets     = config.assets.digest
  self.assets_prefix     = config.assets.prefix
  self.assets_precompile = config.assets.precompile

  self.assets_environment = app.assets
  self.assets_manifest = app.assets_manifest

  self.resolve_assets_with = config.assets.resolve_with

  self.check_precompiled_asset = config.assets.check_precompiled_asset
  self.unknown_asset_fallback  = config.assets.unknown_asset_fallback
  # Expose the app precompiled asset check to the view
  self.precompiled_asset_checker = -> logical_path { app.asset_precompiled? logical_path }
end
databyte commented 8 years ago

I'm having the same issue.

⇒  RAILS_ENV=test RACK_ENV=test bundle exec rake jasmine:ci --trace
** Invoke jasmine:ci (first_time)
** Invoke jasmine:require_json (first_time)
** Execute jasmine:require_json
** Invoke jasmine:require (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute jasmine:require
** Invoke jasmine:configure (first_time)
** Execute jasmine:configure
** Invoke jasmine:configure_plugins (first_time)
** Execute jasmine:configure_plugins
** Execute jasmine:ci
Waiting for jasmine server on 56885...
Waiting for jasmine server on 56885...
Waiting for jasmine server on 56885...
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:56885, CTRL+C to stop
Waiting for jasmine server on 56885...
jasmine server started
!! Unexpected error while processing request: The asset "glyphicons-halflings.png" is not present in the asset pipeline.
^C>> Stopping ...
pauloschilling commented 8 years ago

Same here:

Waiting for jasmine server on 56485...
Waiting for jasmine server on 56485...
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on localhost:56485, CTRL+C to stop
Waiting for jasmine server on 56485...
jasmine server started
Unexpected error while processing request: The asset "font-awesome/fontawesome-webfont.eot" is not present in the asset pipeline.``
junyu-w commented 8 years ago

Same here:

[2016-11-18 23:41:32] INFO  WEBrick 1.3.1
[2016-11-18 23:41:32] INFO  ruby 2.3.1 (2016-04-26) [x86_64-linux]
[2016-11-18 23:41:32] INFO  WEBrick::HTTPServer#start: pid=16640 port=39117
Waiting for jasmine server on 39117...
jasmine server started
[2016-11-18 23:41:33] ERROR Sprockets::Rails::Helper::AssetNotFound: The asset "bootstrap/glyphicons-halflings-regular.eot" is not present in the asset pipeline.

but this only happened to my Travis CI env, tests can pass locally

tansaku commented 7 years ago

I fixed this by locking to rails-sprockets 3.1.1

sPaCeMoNk3yIam commented 7 years ago

This worked for me, too.

slackersoft commented 7 years ago

It looks like Sprockets/Rails are deprecating the option to have assets in both assets and public, if I'm reading it correctly. Does this work if the files are in the app/assets dir?

I'd be happy to review a pull request to set unknown_asset_fallback to true when the method exists to try to get around this error, but it looks like then you should just get a deprecation warning.

Thanks for using Jasmine!

peret commented 7 years ago

I'm having the same problem and am trying to figure out a proper solution. Locking the sprockets-rails version works of course, but I'll probably like to upgrade my gems at some point. My guess is, that there's a bug with jasmine using the assets pipeline properly and it only manifested now, because of the new sprockets behavior. I.e. it is weird that unknown_asset_fallback has no effect, but also it shouldn't even be the case that it should need the fallback. I think @sos4nt is correct in assuming that we need to run the action_view initializer. Because jasmine doesn't seem to trigger that, the config options are never copied and I think that might also explain, why the asset pipeline behaves weirdly in some contexts. It looks like I was able to resolve the issue by requiring action_view/base (thus triggering the initializer in sprockets) instead of including Sprockets::Rails::Helper manually. If you think that's a viable solution, I'd be happy to prepare a PR :)

emwalker commented 7 years ago

Note that the gem in comment https://github.com/jasmine/jasmine-gem/issues/275#issuecomment-264500651 is sprockets-rails 3.1.1, which confused me for a little while.