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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With