spec/unit/project_spec.rb in omnibus-5.5.0 vs spec/unit/project_spec.rb in omnibus-5.6.0

- old
+ new

@@ -85,11 +85,11 @@ it "returns a resources_path" do expect(subject.resources_path).to include("sample/project/resources") end end - describe '#install_dir' do + describe "#install_dir" do it "removes duplicate slashes" do subject.install_dir("///opt//chef") expect(subject.install_dir).to eq("/opt/chef") end @@ -106,11 +106,11 @@ it "is a DSL method" do expect(subject).to have_exposed_method(:install_dir) end end - describe '#default_root' do + describe "#default_root" do context "on Windows" do before { stub_ohai(platform: "windows", version: "2012") } it "returns C:/" do expect(subject.default_root).to eq("C:") @@ -143,23 +143,23 @@ expect(subject.build_git_revision).to eq("632501dde2c41f3bdd988b818b4c008e2ff398dc") end end end - describe '#license' do + describe "#license" do it "sets the default to Unspecified" do expect(subject.license).to eq ("Unspecified") end end - describe '#license_file_path' do + describe "#license_file_path" do it "sets the default to LICENSE" do expect(subject.license_file_path).to eq ("/sample/LICENSE") end end - describe '#dirty!' do + describe "#dirty!" do let(:software) { double(Omnibus::Software) } it "dirties the cache" do subject.instance_variable_set(:@culprit, nil) subject.dirty!(software) @@ -171,11 +171,11 @@ subject.dirty!(software) expect(subject.culprit).to be(software) end end - describe '#dirty?' do + describe "#dirty?" do it "returns true by default" do subject.instance_variable_set(:@culprit, nil) expect(subject).to_not be_dirty end @@ -188,22 +188,22 @@ subject.instance_variable_set(:@culprit, false) expect(subject).to_not be_dirty end end - describe '#<=>' do + describe "#<=>" do let(:chefdk) { described_class.new.tap { |p| p.name("chefdk") } } let(:chef) { described_class.new.tap { |p| p.name("chef") } } let(:ruby) { described_class.new.tap { |p| p.name("ruby") } } it "compares projects by name" do list = [chefdk, chef, ruby] expect(list.sort.map(&:name)).to eq(%w{chef chefdk ruby}) end end - describe '#build_iteration' do + describe "#build_iteration" do let(:fauxhai_options) { Hash.new } before { stub_ohai(fauxhai_options) } context "when on RHEL" do @@ -241,33 +241,33 @@ expect(subject.build_iteration).to eq(1) end end end - describe '#overrides' do + describe "#overrides" do before { subject.overrides.clear } - it 'sets all the things through #overrides' do + it "sets all the things through #overrides" do subject.override(:thing, version: "6.6.6") expect(subject.override(:zlib)).to be_nil end - it 'retrieves the things set through #overrides' do + it "retrieves the things set through #overrides" do subject.override(:thing, version: "6.6.6") expect(subject.override(:thing)[:version]).to eq("6.6.6") end - it 'symbolizes #overrides' do + it "symbolizes #overrides" do subject.override("thing", version: "6.6.6") [:thing, "thing"].each do |thing| expect(subject.override(thing)).not_to be_nil end expect(subject.override(:thing)[:version]).to eq("6.6.6") end end - describe '#ohai' do + describe "#ohai" do before { stub_ohai(platform: "ubuntu", version: "12.04") } it "is a DSL method" do expect(subject).to have_exposed_method(:ohai) end @@ -275,25 +275,25 @@ it "delegates to the Ohai class" do expect(subject.ohai).to be(Ohai) end end - describe '#packagers_for_system' do + describe "#packagers_for_system" do it "returns array of packager objects" do subject.packagers_for_system.each do |packager| expect(packager).to be_a(Packager::Base) end end - it 'calls Packager#for_current_system' do + it "calls Packager#for_current_system" do expect(Packager).to receive(:for_current_system) .and_call_original subject.packagers_for_system end end - describe '#package' do + describe "#package" do it "raises an exception when a block is not given" do expect { subject.package(:foo) }.to raise_error(InvalidValue) end it "adds the block to the list" do @@ -310,27 +310,27 @@ expect(subject.packagers[:foo]).to eq([block_1, block_2]) end end - describe '#packagers' do + describe "#packagers" do it "returns a Hash" do expect(subject.packagers).to be_a(Hash) end it "has a default Hash value of an empty array" do expect(subject.packagers[:foo]).to be_a(Array) expect(subject.packagers[:bar]).to_not be(subject.packagers[:foo]) end end - describe '#compressor' do + describe "#compressor" do it "returns a compressor object" do expect(subject.compressor).to be_a(Compressor::Base) end - it 'calls Compressor#for_current_system' do + it "calls Compressor#for_current_system" do expect(Compressor).to receive(:for_current_system) .and_call_original subject.compressor end @@ -345,11 +345,11 @@ subject.compressor end end - describe '#compress' do + describe "#compress" do it "does not raises an exception when a block is not given" do expect { subject.compress(:foo) }.to_not raise_error end it "adds the compressor to the list" do @@ -371,22 +371,22 @@ expect(subject.compressors[:foo]).to eq([block_1, block_2]) end end - describe '#compressors' do + describe "#compressors" do it "returns a Hash" do expect(subject.compressors).to be_a(Hash) end it "has a default Hash value of an empty array" do expect(subject.compressors[:foo]).to be_a(Array) expect(subject.compressors[:bar]).to_not be(subject.compressors[:foo]) end end - describe '#shasum' do + describe "#shasum" do context "when a filepath is given" do let(:path) { "/project.rb" } let(:file) { double(File) } before do @@ -408,9 +408,40 @@ context "when a filepath is not given" do before { subject.send(:remove_instance_variable, :@filepath) } it "returns the correct shasum" do expect(subject.shasum).to eq("3cc6bd98da4d643b79c71be2c93761a458b442e2931f7d421636f526d0c1e8bf") + end + end + end + + describe "#restore_complete_build" do + let(:cached_build) { double(GitCache) } + let(:first_software) { double(Omnibus::Software) } + let(:last_software) { double(Omnibus::Software) } + + before do + allow(Config).to receive(:use_git_caching).and_return(git_caching) + end + + context "when git caching is enabled" do + let(:git_caching) { true } + + it "restores the last software built" do + expect(subject).to receive(:softwares).and_return([first_software, last_software]) + expect(GitCache).to receive(:new).with(last_software).and_return(cached_build) + expect(cached_build).to receive(:restore_from_cache) + subject.restore_complete_build + end + end + + context "when git caching is disabled" do + let(:git_caching) { false } + + it "does nothing" do + expect(subject).not_to receive(:softwares) + expect(GitCache).not_to receive(:new) + subject.restore_complete_build end end end end end