<commit_before># frozen_string_literal: true

require_relative "shared_examples/invalid_option"

describe Cask::Cmd::Upgrade, :cask do
  it_behaves_like "a command that handles invalid options"

  context "successful upgrade" do
    let(:installed) {
      [
        "outdated/local-caffeine",
        "outdated/local-transmission",
        "outdated/auto-updates",
        "outdated/version-latest",
      ]
    }

    before do
      installed.each { |cask| Cask::Cmd::Install.run(cask) }

      allow_any_instance_of(described_class).to receive(:verbose?).and_return(true)
    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
        local_caffeine = Cask::CaskLoader.load("local-caffeine")
        local_caffeine_path = Cask::Config.global.appdir.join("Caffeine.app")
        local_transmission = Cask::CaskLoader.load("local-transmission")
        local_transmission_path = Cask::Config.global.appdir.join("Transmission.app")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.2")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.60")

        described_class.run

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.3")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.61")
      end

      it "updates only the Casks specified in the command line" do
        local_caffeine = Cask::CaskLoader.load("local-caffeine")
        local_caffeine_path = Cask::Config.global.appdir.join("Caffeine.app")
        local_transmission = Cask::CaskLoader.load("local-transmission")
        local_transmission_path = Cask::Config.global.appdir.join("Transmission.app")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.2")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.60")

        described_class.run("local-caffeine")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.3")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.60")
      end
    end

    describe "with --greedy it checks additional Casks" do
      it 'includes the Casks with "auto_updates true" or "version latest"' do
        local_caffeine = Cask::CaskLoader.load("local-caffeine")
        local_caffeine_path = Cask::Config.global.appdir.join("Caffeine.app")
        auto_updates = Cask::CaskLoader.load("auto-updates")
        auto_updates_path = Cask::Config.global.appdir.join("MyFancyApp.app")
        local_transmission = Cask::CaskLoader.load("local-transmission")
        local_transmission_path = Cask::Config.global.appdir.join("Transmission.app")
        version_latest = Cask::CaskLoader.load("version-latest")
        version_latest_path_1 = Cask::Config.global.appdir.join("Caffeine Mini.app")
        version_latest_path_2 = Cask::Config.global.appdir.join("Caffeine Pro.app")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.2")

        expect(auto_updates).to be_installed
        expect(auto_updates_path).to be_a_directory
        expect(auto_updates.versions).to include("2.57")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.60")

        expect(version_latest).to be_installed
        expect(version_latest_path_1).to be_a_directory
        expect(version_latest_path_2).to be_a_directory
        expect(version_latest.versions).to include("latest")
<commit_msg>Revert "remove flaky cask upgrade test"<commit_after># frozen_string_literal: true

require_relative "shared_examples/invalid_option"

describe Cask::Cmd::Upgrade, :cask do
  it_behaves_like "a command that handles invalid options"

  context "successful upgrade" do
    let(:installed) {
      [
        "outdated/local-caffeine",
        "outdated/local-transmission",
        "outdated/auto-updates",
        "outdated/version-latest",
      ]
    }

    before do
      installed.each { |cask| Cask::Cmd::Install.run(cask) }

      allow_any_instance_of(described_class).to receive(:verbose?).and_return(true)
    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
        local_caffeine = Cask::CaskLoader.load("local-caffeine")
        local_caffeine_path = Cask::Config.global.appdir.join("Caffeine.app")
        local_transmission = Cask::CaskLoader.load("local-transmission")
        local_transmission_path = Cask::Config.global.appdir.join("Transmission.app")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.2")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.60")

        described_class.run

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.3")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.61")
      end

      it "updates only the Casks specified in the command line" do
        local_caffeine = Cask::CaskLoader.load("local-caffeine")
        local_caffeine_path = Cask::Config.global.appdir.join("Caffeine.app")
        local_transmission = Cask::CaskLoader.load("local-transmission")
        local_transmission_path = Cask::Config.global.appdir.join("Transmission.app")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.2")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.60")

        described_class.run("local-caffeine")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.3")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.60")
      end

      it 'updates "auto_updates" and "latest" Casks when their tokens are provided in the command line' do
        local_caffeine = Cask::CaskLoader.load("local-caffeine")
        local_caffeine_path = Cask::Config.global.appdir.join("Caffeine.app")
        auto_updates = Cask::CaskLoader.load("auto-updates")
        auto_updates_path = Cask::Config.global.appdir.join("MyFancyApp.app")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.2")

        expect(auto_updates).to be_installed
        expect(auto_updates_path).to be_a_directory
        expect(auto_updates.versions).to include("2.57")

        described_class.run("local-caffeine", "auto-updates")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.3")

        expect(auto_updates).to be_installed
        expect(auto_updates_path).to be_a_directory
        expect(auto_updates.versions).to include("2.61")
      end
    end

    describe "with --greedy it checks additional Casks" do
      it 'includes the Casks with "auto_updates true" or "version latest"' do
        local_caffeine = Cask::CaskLoader.load("local-caffeine")
        local_caffeine_path = Cask::Config.global.appdir.join("Caffeine.app")
        auto_updates = Cask::CaskLoader.load("auto-updates")
        auto_updates_path = Cask::Config.global.appdir.join("MyFancyApp.app")
        local_transmission = Cask::CaskLoader.load("local-transmission")
        local_transmission_path = Cask::Config.global.appdir.join("Transmission.app")
        version_latest = Cask::CaskLoader.load("version-latest")
        version_latest_path_1 = Cask::Config.global.appdir.join("Caffeine Mini.app")
        version_latest_path_2 = Cask::Config.global.appdir.join("Caffeine Pro.app")

        expect(local_caffeine).to be_installed
        expect(local_caffeine_path).to be_a_directory
        expect(local_caffeine.versions).to include("1.2.2")

        expect(auto_updates).to be_installed
        expect(auto_updates_path).to be_a_directory
        expect(auto_updates.versions).to include("2.57")

        expect(local_transmission).to be_installed
        expect(local_transmission_path).to be_a_directory
        expect(local_transmission.versions).to include("2.60")

        expect(version_latest).to be_installed
        expect(version_latest_path_1).to be_a_directory
        expect(version_latest_path_2).to be_a_directory
        expect(version_latest.versions).to include("latest")

{'fraction_non_alphanumeric': 0.10338931911897818, 'fraction_numerical': 0.008649301015790003, 'mean_word_length': 3.6122448979591835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5822410', 'n_tokens_mistral': 3187, 'n_tokens_neox': 3067, 'n_words': 464}