sprockets installs autoprefixer only if the config/autoprefixer.yml exists (even if empty) (fix issue #54)

did committed Feb 16, 2016
commit d60a9af252b7f2518a81acbc9c4c5d26c06983d0
Showing 2 changed files with 32 additions and 3 deletions
locomotive/steam/initializers/sprockets.rb b/lib/locomotive/steam/initializers/sprockets.rb +7 -3
@@ @@ -47,10 +47,14 @@ module Locomotive::Steam
end
def install_autoprefixer
- file = File.join(root, '..', 'config', 'autoprefixer.yml')
- params = (File.exist?(file) ? ::YAML.load_file(file) : {}).symbolize_keys
+ file = File.join(root, '..', 'config', 'autoprefixer.yml')
- AutoprefixerRails.install(self, params)
+ if File.exists?(file)
+ params = (::YAML.load_file(file) || {}).symbolize_keys
+ AutoprefixerRails.install(self, params)
+
+ Locomotive::Common::Logger.info "Autoprefixer detected and installed".light_white + "\n\n"
+ end
end
def is_java_installed?
spec/unit/initializers/sprockets_spec.rb +25 -0
@@ @@ -22,4 +22,29 @@ describe Locomotive::Steam::SprocketsEnvironment do
end
+ describe '#install_autoprefixer' do
+
+ subject { env }
+
+ context "config/autoprefixer.yml doesn't exist" do
+
+ before { allow(File).to receive(:exists?).and_return false }
+
+ it { expect(AutoprefixerRails).not_to receive(:install); subject }
+
+ end
+
+ context "config/autoprefixer.yml exists" do
+
+ before {
+ allow(File).to receive(:exists?).and_return(true)
+ allow(YAML).to receive(:load_file).and_return({})
+ }
+
+ it { expect(AutoprefixerRails).to receive(:install).and_return(true); subject }
+
+ end
+
+ end
+
end