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

- old
+ new

@@ -42,10 +42,11 @@ 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('gzip_level') 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) @@ -62,20 +63,21 @@ 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('gzip_level') 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.should_receive(:gzip_file).with("#{site_dir}/yes.html", Zlib::BEST_COMPRESSION) + deployer.should_receive(:gzip_file).with("#{site_dir}/yes.js", Zlib::BEST_COMPRESSION) + deployer.should_receive(:gzip_file).with("#{site_dir}/subdir/yes.css", Zlib::BEST_COMPRESSION) + deployer.should_not_receive(:gzip_file).with("#{site_dir}/no.txt", Zlib::BEST_COMPRESSION) + deployer.should_not_receive(:gzip_file).with("#{site_dir}/no.html.gz", Zlib::BEST_COMPRESSION) deployer.gzip_site(site_dir) end it "should gzip only once" do site_tmp_dir = Dir.mktmpdir("site_dir") @@ -86,21 +88,48 @@ 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('gzip_level') 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.should_not_receive(:gzip_file).with("#{site_dir}/yes.html", Zlib::BEST_COMPRESSION) + deployer.should_not_receive(:gzip_file).with("#{site_dir}/yes.js", Zlib::BEST_COMPRESSION) + deployer.should_not_receive(:gzip_file).with("#{site_dir}/subdir/yes.css", Zlib::BEST_COMPRESSION) + deployer.should_not_receive(:gzip_file).with("#{site_dir}/no.txt", Zlib::BEST_COMPRESSION) deployer.gzip_site(site_dir) end + + it "should gzip with the compression level" 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('gzip_level').and_return 6 + 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", 6) + deployer.should_receive(:gzip_file).with("#{site_dir}/yes.js", 6) + deployer.should_receive(:gzip_file).with("#{site_dir}/subdir/yes.css", 6) + deployer.should_not_receive(:gzip_file).with("#{site_dir}/no.txt", 6) + deployer.should_not_receive(:gzip_file).with("#{site_dir}/no.html.gz", 6) + deployer.gzip_site(site_dir) + end + end