kitwalker
kitwalker

Reputation: 982

How can I stop css files from being precompiled in rails test environment

I'm looking for a way to modify my test environment so that the JS files get precompiled but the CSS (SASS) files do not get precompiled.

The reason I want to do this is that I have some capybara feature specs which are running with the js: true flag using phantomjs. These tests take a lot of time before running as I have to set config.assets.compile to true in config/environments/test.rb for the JS feature tests to work and the CSS compilation takes a long time because of my bloated CSS files.

I've tried setting config.assets.compile to [/(?:\/|\\|\A)application\.js$/] only, but I still see SASS compilation happening.

Upvotes: 4

Views: 1189

Answers (1)

kitwalker
kitwalker

Reputation: 982

These are the settings that worked for me finally after some trial and error. Also, it's best to run RAILS_ENV=test rake assets:precompile before the tests.

# in config/environments/test.rb
config.assets.compile = true
config.assets.digest = true
config.assets.precompile = [/(?:\/|\\|\A)application\.js$/]


# in app/view/layouts/application.html.erb
<%= stylesheet_link_tag "application", media: "all" unless Rails.env.test? %>

Upvotes: 3

Related Questions