diff options
| author | L. E. Segovia | 2017-11-12 09:25:15 -0300 | 
|---|---|---|
| committer | L. E. Segovia | 2017-11-13 08:46:08 -0300 | 
| commit | 36fe355159385669fbd5c294b901ed1df5bc745f (patch) | |
| tree | 6aff81617274c53412e034dddf5e0b4227dcb51b /Library/Homebrew/test/cask/cli | |
| parent | 8cc1aea5f07d1fdfb9cf8ae9a5687c571a856312 (diff) | |
| download | brew-36fe355159385669fbd5c294b901ed1df5bc745f.tar.bz2 | |
Add tests for upgrade recovery
Diffstat (limited to 'Library/Homebrew/test/cask/cli')
| -rw-r--r-- | Library/Homebrew/test/cask/cli/upgrade_spec.rb | 82 | 
1 files changed, 70 insertions, 12 deletions
diff --git a/Library/Homebrew/test/cask/cli/upgrade_spec.rb b/Library/Homebrew/test/cask/cli/upgrade_spec.rb index 38e57fc5e..ee7ef2261 100644 --- a/Library/Homebrew/test/cask/cli/upgrade_spec.rb +++ b/Library/Homebrew/test/cask/cli/upgrade_spec.rb @@ -3,21 +3,39 @@ require_relative "shared_examples/invalid_option"  describe Hbc::CLI::Upgrade, :cask do    it_behaves_like "a command that handles invalid options" -  before(:example) do -    installed = -      [ -        "outdated/local-caffeine", -        "outdated/local-transmission", -        "outdated/auto-updates", -      ] +  shared_context "Proper Casks" do +    before(:example) do +      installed = +        [ +          "outdated/local-caffeine", +          "outdated/local-transmission", +          "outdated/auto-updates", +        ] + +      installed.each { |cask| Hbc::CLI::Install.run(cask) } + +      allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) +    end +  end + +  shared_context "Casks that will fail upon upgrade" do +    before(:example) do +      installed = +        [ +          "outdated/bad-checksum", +          "outdated/will-fail-if-upgraded", +        ] -    installed.each { |cask| Hbc::CLI::Install.run(cask) } +      installed.each { |cask| Hbc::CLI::Install.run(cask) } -    allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) +      allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) +    end    end    describe 'without --greedy it ignores the Casks with "version latest" or "auto_updates true"' do -    it "updates all the installed Casks when no token is provided" do +    include_context "Proper Casks" + +    it "and updates all the installed Casks when no token is provided" do        expect(Hbc::CaskLoader.load("local-caffeine")).to be_installed        expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory        expect(Hbc::CaskLoader.load("local-caffeine").versions).to include("1.2.2") @@ -37,7 +55,7 @@ describe Hbc::CLI::Upgrade, :cask do        expect(Hbc::CaskLoader.load("local-transmission").versions).to include("2.61")      end -    it "updates only the Casks specified in the command line" do +    it "and updates only the Casks specified in the command line" do        expect(Hbc::CaskLoader.load("local-caffeine")).to be_installed        expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory        expect(Hbc::CaskLoader.load("local-caffeine").versions).to include("1.2.2") @@ -58,7 +76,7 @@ describe Hbc::CLI::Upgrade, :cask do        expect(Hbc::CaskLoader.load("local-transmission").versions).to include("2.60")      end -    it 'ignores "auto_updates" and "latest" Casks even when their tokens are provided in the command line' do +    it 'and ignores "auto_updates" and "latest" Casks even when their tokens are provided in the command line' do        expect(Hbc::CaskLoader.load("local-caffeine")).to be_installed        expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory        expect(Hbc::CaskLoader.load("local-caffeine").versions).to include("1.2.2") @@ -80,6 +98,8 @@ describe Hbc::CLI::Upgrade, :cask do    end    describe "with --greedy it checks additional Casks" do +    include_context "Proper Casks" +      it 'includes the Casks with "auto_updates true" or "version latest" with --greedy' do        expect(Hbc::CaskLoader.load("auto-updates")).to be_installed        expect(Hbc.appdir.join("MyFancyApp.app")).to be_a_directory @@ -124,4 +144,42 @@ describe Hbc::CLI::Upgrade, :cask do        expect(Hbc::CaskLoader.load("auto-updates").versions).to include("2.61")      end    end + +  describe "handles borked upgrades" do +    include_context "Casks that will fail upon upgrade" + +    output_reverted = Regexp.new <<~EOS +      Warning: Reverting upgrade for Cask .* +    EOS + +    it "by restoring the old Cask if the upgrade's install failed" do +      expect(Hbc::CaskLoader.load("will-fail-if-upgraded")).to be_installed +      expect(Hbc.appdir.join("container")).to be_a_file +      expect(Hbc::CaskLoader.load("will-fail-if-upgraded").versions).to include("1.2.2") + +      expect { +        described_class.run("will-fail-if-upgraded") +      }.to output(output_reverted).to_stderr + +      expect(Hbc::CaskLoader.load("will-fail-if-upgraded")).to be_installed +      expect(Hbc.appdir.join("container")).to be_a_file +      expect(Hbc::CaskLoader.load("will-fail-if-upgraded").versions).to include("1.2.2") +      expect(Hbc::CaskLoader.load("will-fail-if-upgraded").staged_path).to_not exist +    end + +    it "by not restoring the old Cask if the upgrade failed pre-install" do +      expect(Hbc::CaskLoader.load("bad-checksum")).to be_installed +      expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory +      expect(Hbc::CaskLoader.load("bad-checksum").versions).to include("1.2.2") + +      expect { +        described_class.run("bad-checksum") +      }.to_not output(output_reverted).to_stderr + +      expect(Hbc::CaskLoader.load("bad-checksum")).to be_installed +      expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory +      expect(Hbc::CaskLoader.load("bad-checksum").versions).to include("1.2.2") +      expect(Hbc::CaskLoader.load("bad-checksum").staged_path).to_not exist +    end +  end  end  | 
