<commit_before>require 'spec_helper'
require 'capistrano/notifier/statsd'

describe Capistrano::Notifier::StatsD do
  let(:configuration) { Capistrano::Configuration.new }
  subject { described_class.new configuration }

  before :each do
    configuration.load do |configuration|
      set :application, 'example'
    end
  end

  it "sets defaults" do
    subject.send(:host).should == '127.0.0.1'
    subject.send(:port).should == '8125'
    subject.send(:with).should == '1|c'
  end

  it "creates a packet" do
    subject.send(:packet).should == "example.deploy:1|c"
  end

  it "sends a packet" do
    UDPSocket.any_instance.should_receive(:send).once.with(
      "example.deploy:1|c", 0, "127.0.0.1", "8125"
    )

    subject.perform
  end

  context "with a stage" do
    before :each do
      configuration.load do |configuration|
        set :application, 'example'
        set :stage,       'test'
      end
    end

    it "creates a packet" do
      subject.send(:packet).should == "example.test.deploy:1|c"
    end
  end

  context "with statsd options" do
    before :each do
      configuration.load do |configuration|
        set :notifier_statsd_options, {
          :host => '10.0.0.1',
          :port => '1234'
        }

        set :application, 'example'
      end
    end

    it "uses the options" do
      subject.send(:host).should == '10.0.0.1'
      subject.send(:port).should == '1234'
    end
  end

  context "with a gauge" do
    before :each do
      configuration.load do |configuration|
        set :notifier_statsd_options, {
          :with => :gauge
        }

        set :application, 'example'
      end
    end

    it { subject.send(:with).should == "1|g" }
  end

  context "with an uppercase application" do
    before :each do
      configuration.load do
        set :application, 'Example'
      end

      it "lowercases the application" do
        subject.send(:packet).should == "example.deploy:1|c"
      end
    end
  end
end<commit_msg>Use single line blocks where sensible<commit_after>require 'spec_helper'
require 'capistrano/notifier/statsd'

describe Capistrano::Notifier::StatsD do
  let(:configuration) { Capistrano::Configuration.new }
  subject { described_class.new configuration }

  before :each do
    configuration.load { set :application, 'example' }
  end

  it "sets defaults" do
    subject.send(:host).should == '127.0.0.1'
    subject.send(:port).should == '8125'
    subject.send(:with).should == '1|c'
  end

  it "creates a packet" do
    subject.send(:packet).should == "example.deploy:1|c"
  end

  it "sends a packet" do
    UDPSocket.any_instance.should_receive(:send).once.with(
      "example.deploy:1|c", 0, "127.0.0.1", "8125"
    )

    subject.perform
  end

  context "with a stage" do
    before :each do
      configuration.load do
        set :application, 'example'
        set :stage,       'test'
      end
    end

    it "creates a packet" do
      subject.send(:packet).should == "example.test.deploy:1|c"
    end
  end

  context "with statsd options" do
    before :each do
      configuration.load do
        set :notifier_statsd_options, {
          :host => '10.0.0.1',
          :port => '1234'
        }

        set :application, 'example'
      end
    end

    it "uses the options" do
      subject.send(:host).should == '10.0.0.1'
      subject.send(:port).should == '1234'
    end
  end

  context "with a gauge" do
    before :each do
      configuration.load do
        set :notifier_statsd_options, {
          :with => :gauge
        }

        set :application, 'example'
      end
    end

    it { subject.send(:with).should == "1|g" }
  end

  context "with an uppercase application" do
    before :each do
      configuration.load { set :application, 'Example' }

      it "lowercases the application" do
        subject.send(:packet).should == "example.deploy:1|c"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1205927439959121, 'fraction_numerical': 0.022994379151762903, 'mean_word_length': 2.4281961471103326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, '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': '1675364', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1233, 'n_words': 326}