Over a million developers have joined DZone.
Platinum Partner

Precompiling Rails Assets before RSpec/Capybara Integration Tests

· DevOps Zone

The DevOps Zone is brought to you in partnership with HPE.  Learn about the seven KPI’s that create the foundation of DevOps metrics and how it continues to evolve as the DevOps Methodology becomes more engrained in enterprises.  

The first Capybara integration test always tends to timeout when compiling assets on-demand. It’s just damn too slow. Precompile your assets before the test is run.

RSpec.configure do |config|
  config.before :all do
    ENV['PRECOMPILE_ASSETS'] ||= begin
      case self.class.metadata[:type]
      when :feature, :view
        STDOUT.write "Precompiling assets..."
        Sprockets::StaticCompiler.new(
          Rails.application.assets,
          File.join(Rails.public_path, Rails.configuration.assets.prefix),
          Rails.configuration.assets.precompile,
          manifest_path: Rails.configuration.assets.manifest,
          digest: Rails.configuration.assets.digest,
          manifest: false).compile
        STDOUT.puts " done."
        Time.now.to_s
      end
    end
  end
end


The DevOps Zone is brought to you in partnership with HPE.  Discover the Top 5 predictions for DevOps and the central role they will play as enterprises begin to modernize legacy applications.

Topics:

Published at DZone with permission of Daniel Doubrovkine .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}