Monday, March 2, 2015

AssetFilteredError: Assets filtered out and will not be served

If you've decided to use the Teaspoon gem for running your JS tests, you may have encountered this error when trying to navigate to your test suite:
 Error: Sprockets::Rails::Helper::AssetFilteredError: Asset filtered out and will not be served:   
 add `Rails.application.config.assets.precompile += %w( teaspoon.css )` to `config/initializers/assets.rb` and restart your server  
Unfortunately, this is an issue with Teaspoon and newer (>4.0) versions of Rails. For some reason, the asset paths for Teaspoon are no longer included in the list of assets that are automatically precompiled. Therefore, you must add them to your config/initializers/assets.rb file like so:
 unless Rails.env.production?  
  Rails.application.config.assets.precompile += %w(  
   # other assets  
Note: I added a surrounding check for production. Since Teaspoon is a testing gem, you shouldn't be using it in production, nor should you need its assets. If you have assets in this file that you need for production, you can separately add them with another addition to Rails.application.config.assets.precompile.