Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude *.spec.js files in Rails asset pipeline (application.js)

I'm attempting to follow John Papa's AngularJs 1.x styleguide (organising tests) and place *.spec.js files (to be executed using Karma) next to client code, which results in files such as some.filter.js and some.filter.spec.js being place next to one another.

However, what I need to avoid, is including the *.spec.js files in the assets pipeline.

The only options I see for now are either avoiding using //= require_tree . in the application.js file and specifying every single file explicitly, or giving up on keeping spec files next to the code.

Is there any better way of achieving the desired behaviour?

(I'm using sprockets 3.5.2 and rails 4.2.6)

like image 850
konradstrack Avatar asked Mar 10 '16 11:03

konradstrack


1 Answers

Sprockets itself does not implement file globbing (yet) - this can only achieved by providing a custom DirectiveProcessor. Luckily, there is already a gem providing exactly what you want: https://github.com/backupify/sprockets-glob

From the documentation:

# config/initializers/sprockets.rb
require 'sprockets/glob'
Rails.application.assets.register_processor('application/javascript', Sprockets::Glob::DirectiveProcessor)

# application.js
//= require_glob features/**/*.js
//= stub_glob features/**/*test.js
like image 67
defsprite Avatar answered Oct 26 '22 11:10

defsprite