spec/deploy_spec.rb in awestruct-0.5.4.beta1 vs spec/deploy_spec.rb in awestruct-0.5.4.rc

- old
+ new

@@ -1,6 +1,6 @@ - +require 'spec_helper' require 'awestruct/cli/deploy' describe Awestruct::CLI::Deploy do it "should use a given deploy[:type]" do @@ -34,8 +34,73 @@ end it "should work with strings for values" do deployer = Awestruct::CLI::Deploy.new({}, {'host' => 'github_pages'}) deployer.deploy_type.should == :github_pages + end + + it "should gzip if deploy['gzip'] is true" do + site_config = mock + site_config.stub(:output_dir).and_return '_site' + + deploy_config = mock + deploy_config.stub(:[]).with('gzip').and_return true + deploy_config.stub(:[]).with('source_dir').and_return '.' + deploy_config.stub(:[]).with('scm').and_return nil + deploy_config.stub(:[]).with('uncommitted').and_return true + + deployer = Awestruct::Deploy::Base.new(site_config, deploy_config) + deployer.should_receive(:gzip_site) + deployer.run + end + + it "should only gzip html, css and js files" do + site_tmp_dir = Dir.mktmpdir("site_dir") + site_src_dir = File.join(File.dirname(__FILE__), 'test-data/gzip') + FileUtils.cp_r(site_src_dir, site_tmp_dir) + site_dir = "#{site_tmp_dir}/gzip" + + site_config = mock + site_config.stub(:output_dir).and_return "#{site_dir}" + + deploy_config = mock + deploy_config.stub(:[]).with('gzip').and_return true + deploy_config.stub(:[]).with('source_dir').and_return '.' + deploy_config.stub(:[]).with('scm').and_return nil + deploy_config.stub(:[]).with('uncommitted').and_return nil + + deployer = Awestruct::Deploy::Base.new(site_config, deploy_config) + deployer.should_receive(:gzip_file).with("#{site_dir}/yes.html") + deployer.should_receive(:gzip_file).with("#{site_dir}/yes.js") + deployer.should_receive(:gzip_file).with("#{site_dir}/subdir/yes.css") + deployer.should_not_receive(:gzip_file).with("#{site_dir}/no.txt") + deployer.should_not_receive(:gzip_file).with("#{site_dir}/no.html.gz") + deployer.gzip_site(site_dir) + end + + it "should gzip only once" do + site_tmp_dir = Dir.mktmpdir("site_dir") + site_src_dir = File.join(File.dirname(__FILE__), 'test-data/gzip') + FileUtils.cp_r(site_src_dir, site_tmp_dir) + site_dir = "#{site_tmp_dir}/gzip" + + site_config = mock + site_config.stub(:output_dir).and_return "#{site_dir}" + + deploy_config = mock + deploy_config.stub(:[]).with('gzip').and_return true + deploy_config.stub(:[]).with('source_dir').and_return '.' + deploy_config.stub(:[]).with('scm').and_return nil + deploy_config.stub(:[]).with('uncommitted').and_return nil + + deployer = Awestruct::Deploy::Base.new(site_config, deploy_config) + deployer.gzip_site(site_dir) + + # Gzip only once + deployer.should_not_receive(:gzip_file).with("#{site_dir}/yes.html") + deployer.should_not_receive(:gzip_file).with("#{site_dir}/yes.js") + deployer.should_not_receive(:gzip_file).with("#{site_dir}/subdir/yes.css") + deployer.should_not_receive(:gzip_file).with("#{site_dir}/no.txt") + deployer.gzip_site(site_dir) end end