<commit_before>require 'spec_helper'


describe Config do
  Config = Travis::Worker::Config

  before(:each) do
    Config.send :public, *Config.protected_instance_methods
    Config.any_instance.stubs(:read_yml).returns({})
    File.stubs(:exists?).returns(true)
  end

  let(:config) { Config.new }

  it "looks for a file ./config/worker.yml" do
    File.stubs(:exists?).with('./config/worker.yml').returns(true)
    config.path.should eql './config/worker.yml'
  end

  it "looks for a file ~/.worker.yml" do
    File.stubs(:exists?).with('./config/worker.yml').returns(false)
    File.stubs(:exists?).with('~/.worker.yml').returns(true)
    config.path.should eql '~/.worker.yml'
  end

  it "reads ./config/worker.yml first, ./config/worker.[env].yml second and merges them" do
    File.stubs(:exists?).with('./config/worker.yml').returns(true)

    Config.any_instance.stubs(:read_yml).with('./config/worker.yml').returns('env' => 'staging', 'staging' => { 'foo' => 'foo' })
    Config.any_instance.stubs(:read_yml).with('./config/worker.staging.yml').returns('bar' => 'bar')

    config.read['env'].should eql 'staging'
    config.read['foo'].should eql 'foo'
    config.read['bar'].should eql 'bar'
  end

  it 'vms includes the Vms module' do
    Config.any_instance.stubs(:read_yml).returns({ 'vms' => { 'count' => 5 } })
    config.vms.meta_class.included_modules.include?(Config::Vms).should be_true
    config.vms.count.should eql 5
  end

  context :defaults do
    it 'before_script timeout defaults to 120' do
      config.timeouts.before_script.should == 300
    end

    it 'after_script timeout defaults to 120' do
      config.timeouts.after_script.should == 120
    end

    it 'script timeout defaults to 600' do
      config.timeouts.script.should == 600
    end

    it 'bundle timeout defaults to 300' do
      config.timeouts.install.should == 300
    end

    it 'queue defaults to builds' do<commit_msg>remove the constant warning from config_spec.rb<commit_after>require 'spec_helper'


describe Travis::Worker::Config do
  before(:each) do
    Travis::Worker::Config.send :public, *Travis::Worker::Config.protected_instance_methods
    Travis::Worker::Config.any_instance.stubs(:read_yml).returns({})
    File.stubs(:exists?).returns(true)
  end

  let(:config) { Travis::Worker::Config.new }

  it "looks for a file ./config/worker.yml" do
    File.stubs(:exists?).with('./config/worker.yml').returns(true)
    config.path.should eql './config/worker.yml'
  end

  it "looks for a file ~/.worker.yml" do
    File.stubs(:exists?).with('./config/worker.yml').returns(false)
    File.stubs(:exists?).with('~/.worker.yml').returns(true)
    config.path.should eql '~/.worker.yml'
  end

  it "reads ./config/worker.yml first, ./config/worker.[env].yml second and merges them" do
    File.stubs(:exists?).with('./config/worker.yml').returns(true)

    Travis::Worker::Config.any_instance.stubs(:read_yml).with('./config/worker.yml').returns('env' => 'staging', 'staging' => { 'foo' => 'foo' })
    Travis::Worker::Config.any_instance.stubs(:read_yml).with('./config/worker.staging.yml').returns('bar' => 'bar')

    config.read['env'].should eql 'staging'
    config.read['foo'].should eql 'foo'
    config.read['bar'].should eql 'bar'
  end

  it 'vms includes the Vms module' do
    Travis::Worker::Config.any_instance.stubs(:read_yml).returns({ 'vms' => { 'count' => 5 } })
    config.vms.meta_class.included_modules.include?(Travis::Worker::Config::Vms).should be_true
    config.vms.count.should eql 5
  end

  context :defaults do
    it 'before_script timeout defaults to 120' do
      config.timeouts.before_script.should == 300
    end

    it 'after_script timeout defaults to 120' do
      config.timeouts.after_script.should == 120
    end

    it 'script timeout defaults to 600' do
      config.timeouts.script.should == 600
    end

    it 'bundle timeout defaults to 300' do
      config.timeouts.install.should == 300
    end

    it 'queue defaults to builds' do
{'fraction_non_alphanumeric': 0.15872223608684802, 'fraction_numerical': 0.012977289742949838, 'mean_word_length': 3.6550522648083623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4697049', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1288, 'n_words': 274}