<commit_before>require 'spec_helper'
require './libraries/default'

describe Ark::ResourceDefaults do
  before(:each) do
    allow_any_instance_of(Ark::ResourceDefaults).to receive(:file_cache_path).and_return('/var/chef/cache')
  end

  describe '#extension' do
    it 'returns the extension parameter specified on the resource' do
      resource = double(extension: 'me')
      defaults = described_class.new(resource)
      expect(defaults.extension).to eq 'me'
    end

    context 'when the extension is nil' do
      it 'creates an extension based on the file specified in the URL' do
        resource = double(extension: nil, url: 'http://localhost/file.tgz')
        defaults = described_class.new(resource)
        expect(defaults.extension).to eq 'tgz'
      end

      it 'creates an extension based on the file specified in the URL (and not other words with similar names to extensions)' do
        resource = double(extension: nil, url: 'https://jar.binfiles.tbz/file.tar.bz2')
        defaults = described_class.new(resource)
        expect(defaults.extension).to eq 'tar.bz2'
      end

      it 'creates an extension for tar files' do
        resource = double(extension: nil, url: 'https://jar.binfiles.tbz/file.tar')
        defaults = described_class.new(resource)
        expect(defaults.extension).to eq 'tar'
      end

      context 'when the archive format is not supported' do
        it 'it returns a nil extension' do
          resource = double(extension: nil, url: 'http://localhost/file.stuffit')
          defaults = described_class.new(resource)
          expect(defaults.extension).to eq nil
        end
      end

      context 'when the url contains a query string' do
        it 'creates an extension based on the file specified in the URL' do
          resource = double(extension: nil, url: 'http://localhost/file.version.txz-bin?latest=true')
          defaults = described_class.new(resource)
          expect(defaults.extension).to eq 'txz'<commit_msg>Add test for sniffing 7z file extension from URL<commit_after>require 'spec_helper'
require './libraries/default'

describe Ark::ResourceDefaults do
  before(:each) do
    allow_any_instance_of(Ark::ResourceDefaults).to receive(:file_cache_path).and_return('/var/chef/cache')
  end

  describe '#extension' do
    it 'returns the extension parameter specified on the resource' do
      resource = double(extension: 'me')
      defaults = described_class.new(resource)
      expect(defaults.extension).to eq 'me'
    end

    context 'when the extension is nil' do
      it 'creates an extension based on the file specified in the URL' do
        resource = double(extension: nil, url: 'http://localhost/file.tgz')
        defaults = described_class.new(resource)
        expect(defaults.extension).to eq 'tgz'
      end

      it 'creates an extension based on the file specified in the URL (and not other words with similar names to extensions)' do
        resource = double(extension: nil, url: 'https://jar.binfiles.tbz/file.tar.bz2')
        defaults = described_class.new(resource)
        expect(defaults.extension).to eq 'tar.bz2'
      end

      it 'creates an extension for tar files' do
        resource = double(extension: nil, url: 'https://jar.binfiles.tbz/file.tar')
        defaults = described_class.new(resource)
        expect(defaults.extension).to eq 'tar'
      end

      it 'creates an extension for 7z files' do
        resource = double(extension: nil, url: 'https://sourceforge.net/projects/boost/files/boost/1.62.0/boost_1_62_0.7z')
        defaults = described_class.new(resource)
        expect(defaults.extension).to eq '7z'
      end

      context 'when the archive format is not supported' do
        it 'it returns a nil extension' do
          resource = double(extension: nil, url: 'http://localhost/file.stuffit')
          defaults = described_class.new(resource)
          expect(defaults.extension).to eq nil
        end
      end

      context 'when the url contains a query string' do
        it 'creates an extension based on the file specified in the URL' do
          resource = double(extension: nil, url: 'http://localhost/file.version.txz-bin?latest=true')
          defaults = described_class.new(resource)
          expect(defaults.extension).to eq 'txz'
{'fraction_non_alphanumeric': 0.09746452663410095, 'fraction_numerical': 0.0037217957664573155, 'mean_word_length': 2.9814814814814814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, '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': '5437748', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1168, 'n_words': 380}