<commit_before>require 'spec_helper'
require 'capistrano/srv_hosts'

describe Capistrano::SRVHosts do
  before(:all) do
    @test_data = [
      srv_record(15, 1000, 0, 'server04.example.com'),
      srv_record(10, 1000, 0, 'server03.example.com'),
      srv_record(10, 1000, 0, 'server02.example.com'),
      srv_record(10, 1005, 0, 'server01.example.com')
    ]
  end

  before(:each) do 
    @configuration = Capistrano::Configuration.new
    Capistrano::SRVHosts.load_into(@configuration)
  end

  it 'should load instance methods into Capistrano' do
    @configuration.methods.should include(:srv_hosts)
    @configuration.methods.should include(:srv_role)
  end

  describe '#srv_hosts' do
    it 'should query DNS and cache results' do
      Resolv::DNS.any_instance.should_receive(:getresources).with('_test._tcp.example.com', Resolv::DNS::Resource::IN::SRV).exactly(1).times.and_return(@test_data)
      @configuration.srv_hosts('_test._tcp.example.com')
      @configuration.srv_hosts('_test._tcp.example.com')
    end

    it 'should sort the results properly' do
      Resolv::DNS.any_instance.should_receive(:getresources).with('_test._tcp.example.com', Resolv::DNS::Resource::IN::SRV).exactly(1).times.and_return(@test_data)
      res = @configuration.srv_hosts('_test._tcp.example.com')
      res.size.should eq(4)
      res.should eq(['server02.example.com', 'server03.example.com', 'server01.example.com', 'server04.example.com'])
    end
  end

  describe '#srv_role' do
    it 'should define the role' do
      @configuration.should_receive(:srv_hosts).and_return(['server01.example.com', 'server02.example.com'])
      @configuration.srv_role :app, '_test._tcp.example.com'
      @configuration.roles[:app].servers.size.should eq(2)
      @configuration.roles[:app].servers.map(&:to_s).should eq(['server01.example.com', 'server02.example.com'])
    end

    it 'should handle role params' do<commit_msg>Fix module name case in specs<commit_after>require 'spec_helper'
require 'capistrano/srv_hosts'

describe Capistrano::SrvHosts do
  before(:all) do
    @test_data = [
      srv_record(15, 1000, 0, 'server04.example.com'),
      srv_record(10, 1000, 0, 'server03.example.com'),
      srv_record(10, 1000, 0, 'server02.example.com'),
      srv_record(10, 1005, 0, 'server01.example.com')
    ]
  end

  before(:each) do 
    @configuration = Capistrano::Configuration.new
    Capistrano::SrvHosts.load_into(@configuration)
  end

  it 'should load instance methods into Capistrano' do
    @configuration.methods.should include(:srv_hosts)
    @configuration.methods.should include(:srv_role)
  end

  describe '#srv_hosts' do
    it 'should query DNS and cache results' do
      Resolv::DNS.any_instance.should_receive(:getresources).with('_test._tcp.example.com', Resolv::DNS::Resource::IN::SRV).exactly(1).times.and_return(@test_data)
      @configuration.srv_hosts('_test._tcp.example.com')
      @configuration.srv_hosts('_test._tcp.example.com')
    end

    it 'should sort the results properly' do
      Resolv::DNS.any_instance.should_receive(:getresources).with('_test._tcp.example.com', Resolv::DNS::Resource::IN::SRV).exactly(1).times.and_return(@test_data)
      res = @configuration.srv_hosts('_test._tcp.example.com')
      res.size.should eq(4)
      res.should eq(['server02.example.com', 'server03.example.com', 'server01.example.com', 'server04.example.com'])
    end
  end

  describe '#srv_role' do
    it 'should define the role' do
      @configuration.should_receive(:srv_hosts).and_return(['server01.example.com', 'server02.example.com'])
      @configuration.srv_role :app, '_test._tcp.example.com'
      @configuration.roles[:app].servers.size.should eq(2)
      @configuration.roles[:app].servers.map(&:to_s).should eq(['server01.example.com', 'server02.example.com'])
    end

    it 'should handle role params' do
{'fraction_non_alphanumeric': 0.14544513457556935, 'fraction_numerical': 0.028985507246376812, 'mean_word_length': 4.353185595567867, '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': '4020299', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1295, 'n_words': 220}