<commit_before>require 'cf-deploy'
require 'rake'

describe CF::Deploy do
  before :each do
    Rake::Task.clear
  end

  context '.install_tasks!' do
    it 'should install task for each manifest' do
      Dir.chdir('spec/') do
        described_class.install_tasks!
      end

      expect(Rake::Task['cf:deploy:staging']).to be_a(Rake::Task)
      expect(Rake::Task['cf:deploy:production']).to be_a(Rake::Task)
    end

    it 'should install login task' do
      Dir.chdir('spec/') do
        described_class.install_tasks!
      end

      expect(Rake::Task['cf:login']).to be_a(Rake::Task)
    end

    it 'should install a login task as a prerequisite for deploy tasks' do
      Dir.chdir('spec/') do
        described_class.install_tasks!
      end

      expect(Rake::Task['cf:deploy:staging'].prerequisite_tasks[0]).to be(Rake::Task['cf:login'])
    end

    it 'should install tasks with prerequisites' do
      expected_task_1 = Rake::Task.define_task('asset:precompile')
      expected_task_2 = Rake::Task.define_task(:clean)

      Dir.chdir('spec/') do
        described_class.install_tasks! do
          environment :staging => 'asset:precompile'
          environment :production => ['asset:precompile', :clean]
        end
      end

      expect(Rake::Task['cf:deploy:staging'].prerequisite_tasks[1]).to be(expected_task_1)
      expect(Rake::Task['cf:deploy:production'].prerequisite_tasks[2]).to be(expected_task_2)
    end

    it 'should have a configurable manifest glob options' do
      Dir.chdir('spec/') do
        described_class.install_tasks! do
          manifest_glob 'manifests/staging.yml'
        end
      end

      expect(Rake::Task.tasks.count).to eq(2)
    end
  end

  context 'Rake::Task[cf:login]' do
    it 'should run `cf login` without arguments if none provided' do
      described_class.install_tasks!
      expect(Kernel).to receive(:system).with('cf login')
      Rake::Task['cf:login'].invoke
    end

    it 'should include defined details' do
      described_class.install_tasks! do
        api 'api.run.pivotal.io'
      end

      expect(Kernel).to receive(:system).with('cf login -a api.run.pivotal.io')
      Rake::Task['cf:login'].invoke
    end

    it 'should include all defined details' do
      described_class.install_tasks! do
        api 'api'
        username 'test'
        password '<PASSWORD>'
        organisation 'org'
        space 'space'
      end

      expect(Kernel).to receive(:system).with('cf login -a api -u test -p pass -o org -s space')
      Rake::Task['cf:login'].invoke
    end

    it 'should include all details provided in ENV' do
      {'CF_API' => 'api',
       'CF_USERNAME' => 'test',
       'CF_PASSWORD' => '<PASSWORD>',
       'CF_ORGANISATION' => 'org',
       'CF_SPACE' => 'space'}.each do |(k, v)|
        expect(ENV).to receive(:[]).with(k).and_return(v).at_least(:once)
      end

      expect(Kernel).to receive(:system).with('cf login -a api -u test -p pass -o org -s space')
      described_class.install_tasks!
      Rake::Task['cf:login'].invoke
    end

    it 'should mix and match ENV and defined details with ENV having precedence' do
      {'CF_API' => nil,
       'CF_USERNAME' => 'test',
       'CF_PASSWORD' => '<PASSWORD>',
       'CF_ORGANISATION' => 'org',
       'CF_SPACE' => nil}.each do |(k, v)|
        expect(ENV).to receive(:[]).with(k).and_return(v).at_least(:once)
      end

      expect(Kernel).to receive(:system).with('cf login -a api -u test -p pass -o org')

      described_class.install_tasks! do
        api 'api'
        organisation 'will be overridden by ENV[CF_ORGANISATION]'
      end
      
      Rake::Task['cf:login'].invoke
    end<commit_msg>Use :test env instead of :production<commit_after>require 'cf-deploy'
require 'rake'

describe CF::Deploy do
  before :each do
    Rake::Task.clear
  end

  context '.install_tasks!' do
    it 'should install task for each manifest' do
      Dir.chdir('spec/') do
        described_class.install_tasks!
      end

      expect(Rake::Task['cf:deploy:staging']).to be_a(Rake::Task)
      expect(Rake::Task['cf:deploy:test']).to be_a(Rake::Task)
    end

    it 'should install login task' do
      Dir.chdir('spec/') do
        described_class.install_tasks!
      end

      expect(Rake::Task['cf:login']).to be_a(Rake::Task)
    end

    it 'should install a login task as a prerequisite for deploy tasks' do
      Dir.chdir('spec/') do
        described_class.install_tasks!
      end

      expect(Rake::Task['cf:deploy:staging'].prerequisite_tasks[0]).to be(Rake::Task['cf:login'])
    end

    it 'should install tasks with prerequisites' do
      expected_task_1 = Rake::Task.define_task('asset:precompile')
      expected_task_2 = Rake::Task.define_task(:clean)

      Dir.chdir('spec/') do
        described_class.install_tasks! do
          environment :staging => 'asset:precompile'
          environment :test => ['asset:precompile', :clean]
        end
      end

      expect(Rake::Task['cf:deploy:staging'].prerequisite_tasks[1]).to be(expected_task_1)
      expect(Rake::Task['cf:deploy:test'].prerequisite_tasks[2]).to be(expected_task_2)
    end

    it 'should have a configurable manifest glob options' do
      Dir.chdir('spec/') do
        described_class.install_tasks! do
          manifest_glob 'manifests/staging.yml'
        end
      end

      expect(Rake::Task.tasks.count).to eq(2)
    end
  end

  context 'Rake::Task[cf:login]' do
    it 'should run `cf login` without arguments if none provided' do
      described_class.install_tasks!
      expect(Kernel).to receive(:system).with('cf login')
      Rake::Task['cf:login'].invoke
    end

    it 'should include defined details' do
      described_class.install_tasks! do
        api 'api.run.pivotal.io'
      end

      expect(Kernel).to receive(:system).with('cf login -a api.run.pivotal.io')
      Rake::Task['cf:login'].invoke
    end

    it 'should include all defined details' do
      described_class.install_tasks! do
        api 'api'
        username 'test'
        password '<PASSWORD>'
        organisation 'org'
        space 'space'
      end

      expect(Kernel).to receive(:system).with('cf login -a api -u test -p pass -o org -s space')
      Rake::Task['cf:login'].invoke
    end

    it 'should include all details provided in ENV' do
      {'CF_API' => 'api',
       'CF_USERNAME' => 'test',
       'CF_PASSWORD' => '<PASSWORD>',
       'CF_ORGANISATION' => 'org',
       'CF_SPACE' => 'space'}.each do |(k, v)|
        expect(ENV).to receive(:[]).with(k).and_return(v).at_least(:once)
      end

      expect(Kernel).to receive(:system).with('cf login -a api -u test -p pass -o org -s space')
      described_class.install_tasks!
      Rake::Task['cf:login'].invoke
    end

    it 'should mix and match ENV and defined details with ENV having precedence' do
      {'CF_API' => nil,
       'CF_USERNAME' => 'test',
       'CF_PASSWORD' => '<PASSWORD>',
       'CF_ORGANISATION' => 'org',
       'CF_SPACE' => nil}.each do |(k, v)|
        expect(ENV).to receive(:[]).with(k).and_return(v).at_least(:once)
      end

      expect(Kernel).to receive(:system).with('cf login -a api -u test -p pass -o org')

      described_class.install_tasks! do
        api 'api'
        organisation 'will be overridden by ENV[CF_ORGANISATION]'
      end

      Rake::Task['cf:login'].invoke
    end
{'fraction_non_alphanumeric': 0.13497763924651038, 'fraction_numerical': 0.002168315489903781, 'mean_word_length': 2.7962962962962963, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, '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': '2449547', 'n_tokens_mistral': 2437, 'n_tokens_neox': 2353, 'n_words': 570}