<commit_before>require 'spec_helper'

describe Jenkins::Peace do

  def helper
    Jenkins::Peace
  end

  JENKINS_WAR_URL    = 'http://mirrors.jenkins-ci.org/war/'
  BASE_PATH          = File.join(ENV['HOME'], '.jenkins')
  WAR_FILES_CACHE    = File.join(ENV['HOME'], '.jenkins', 'war-files')
  WAR_UNPACKED_CACHE = File.join(ENV['HOME'], '.jenkins', 'wars')
  SERVER_PATH        = File.join(ENV['HOME'], '.jenkins', 'server')


  def infos
    {
      base_path:          BASE_PATH,
      war_files_cache:    WAR_FILES_CACHE,
      war_unpacked_cache: WAR_UNPACKED_CACHE,
      server_path:        SERVER_PATH,
      jenkins_war_url:    JENKINS_WAR_URL
    }
  end


  describe '.jenkins_war_url' do
    it { expect(helper.jenkins_war_url).to eq JENKINS_WAR_URL }
  end


  describe '.base_path' do
    it { expect(helper.base_path).to eq BASE_PATH }
  end


  describe '.war_files_cache' do
    it { expect(helper.war_files_cache).to eq WAR_FILES_CACHE }
  end


  describe '.war_unpacked_cache' do
    it { expect(helper.war_unpacked_cache).to eq WAR_UNPACKED_CACHE }
  end


  describe '.server_path' do
    it { expect(helper.server_path).to eq SERVER_PATH }
  end


  describe '.infos' do
    it { expect(helper.infos).to eq infos }
  end


  def stub_with_return(method, value)
    expect_any_instance_of(Jenkins::Peace).to receive(method).at_least(:once).and_return(value)
  end


  describe '.list' do
    context 'when no war file is installed' do
      it 'should return empty array' do
        stub_with_return(:all_war_files, [])
        expect(helper.list).to eq []
      end
    end

    context 'when war files are installed' do
      it 'should return a list of war files' do
        stub_with_return(:all_war_files, ['1.629', '1.628', '1.630'])
        expect(helper.list.first).to be_instance_of(Jenkins::Peace::WarFile)
        expect(helper.latest_war_file.version).to eq '1.630'
      end
    end
  end


  describe '.latest_war_file' do
    context 'when no war file is installed' do
      it 'should return nil' do
        stub_with_return(:all_war_files, [])
        expect(helper.latest_war_file).to be nil
      end
    end

    context 'when war files are installed' do
      it 'should return a list of war files' do
        stub_with_return(:all_war_files, ['1.629', '1.628'])
        expect(helper.latest_war_file).to be_instance_of(Jenkins::Peace::WarFile)
        expect(helper.latest_war_file.version).to eq '1.629'
      end
    end
  end


  describe '.latest_version' do
    context 'when no war file is installed' do
      it 'should return nil' do
        stub_with_return(:all_war_files, [])
        expect(helper.latest_version).to be nil
      end
    end

    context 'when war files are installed' do
      it 'should return a list of war files' do
        stub_with_return(:all_war_files, ['1.629', '1.628'])
        expect(helper.latest_version).to eq File.join(ENV['HOME'], '.jenkins/wars/1.629/WEB-INF/lib/jenkins-core-1.629.jar')
      end
    end
  end


  describe '.clean!' do
    it 'should remove all war files' do
      stub_with_return(:all_war_files, ['1.629', '1.628'])
      allow_any_instance_of(Jenkins::Peace::WarFile).to receive(:remove!)
      helper.clean!
    end
  end

<commit_msg>Fix tests<commit_after>require 'spec_helper'

describe Jenkins::Peace do

  def helper
    Jenkins::Peace
  end

  JENKINS_WAR_URL    = 'http://mirrors.jenkins-ci.org/war/'
  BASE_PATH          = File.join(ENV['HOME'], '.jenkins')
  WAR_FILES_CACHE    = File.join(ENV['HOME'], '.jenkins', 'war-files')
  WAR_UNPACKED_CACHE = File.join(ENV['HOME'], '.jenkins', 'wars')
  SERVER_PATH        = File.join(ENV['HOME'], '.jenkins', 'server')


  def infos
    {
      base_path:          BASE_PATH,
      war_files_cache:    WAR_FILES_CACHE,
      war_unpacked_cache: WAR_UNPACKED_CACHE,
      server_path:        SERVER_PATH,
      jenkins_war_url:    JENKINS_WAR_URL
    }
  end


  describe '.jenkins_war_url' do
    it { expect(helper.jenkins_war_url).to eq JENKINS_WAR_URL }
  end


  describe '.base_path' do
    it { expect(helper.base_path).to eq BASE_PATH }
  end


  describe '.war_files_cache' do
    it { expect(helper.war_files_cache).to eq WAR_FILES_CACHE }
  end


  describe '.war_unpacked_cache' do
    it { expect(helper.war_unpacked_cache).to eq WAR_UNPACKED_CACHE }
  end


  describe '.server_path' do
    it { expect(helper.server_path).to eq SERVER_PATH }
  end


  describe '.infos' do
    it { expect(helper.infos).to eq infos }
  end


  def stub_with_return(method, value)
    expect_any_instance_of(Jenkins::Peace).to receive(method).at_least(:once).and_return(value)
  end


  describe '.list' do
    context 'when no war file is installed' do
      it 'should return empty array' do
        stub_with_return(:all_war_files, [])
        expect(helper.list).to eq []
      end
    end

    context 'when war files are installed' do
      it 'should return a list of war files' do
        stub_with_return(:all_war_files, ['1.629', '1.628', '1.630'])
        allow_any_instance_of(Jenkins::Peace::WarFile).to receive(:installed?).and_return(true)
        expect(helper.list.first).to be_instance_of(Jenkins::Peace::WarFile)
        expect(helper.list.first.version).to eq '1.630'
      end
    end
  end


  describe '.latest_war_file' do
    context 'when no war file is installed' do
      it 'should return nil' do
        stub_with_return(:all_war_files, [])
        expect(helper.latest_war_file).to be nil
      end
    end

    context 'when war files are installed' do
      it 'should return the last war file installed' do
        stub_with_return(:all_war_files, ['1.629', '1.628'])
        allow_any_instance_of(Jenkins::Peace::WarFile).to receive(:installed?).and_return(true)
        expect(helper.latest_war_file).to be_instance_of(Jenkins::Peace::WarFile)
        expect(helper.latest_war_file.version).to eq '1.629'
      end
    end
  end


  describe '.latest_version' do
    context 'when no war file is installed' do
      it 'should return nil' do
        stub_with_return(:all_war_files, [])
        expect(helper.latest_version).to be nil
      end
    end

    context 'when war files are installed' do
      it 'should return the classpath of the last war file installed' do
        stub_with_return(:all_war_files, ['1.629', '1.628'])
        allow_any_instance_of(Jenkins::Peace::WarFile).to receive(:installed?).and_return(true)
        expect(helper.latest_version).to eq File.join(ENV['HOME'], '.jenkins/wars/1.629/WEB-INF/lib/jenkins-core-1.629.jar')
      end
    end
  end


  describe '.clean!' do
    it 'should remove all war files' do
      stub_with_return(:all_war_files, ['1.629', '1.628'])
      allow_any_instance_of(Jenkins::Peace::WarFile).to receive(:remove!)
      helper.clean!
    end
  end


{'fraction_non_alphanumeric': 0.112889019377569, 'fraction_numerical': 0.015267175572519083, 'mean_word_length': 2.9935521688159437, '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': '1053954', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2326, 'n_words': 526}