Today I Learned

A Hashrocket project

Run webpack before tests in Rails 5.1 and RSpec

When running tests via RSpec in Rails 5.1 with Webpack support (via the built-in webpacker gem) you need to have Webpack compile your front-end assets before running your tests. To achieve that in RSpec add the following to your rails_helper.rb:

config.before(:suite) do
  # compile front-end and load manifest
  `bin/webpack`
  Webpacker::Manifest.load
end
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket and we'd love to take a look at your project. Contact us and find out how we can help you.