<commit_before>require "spec_helper"

require "henson/source/github_tarball"

describe Henson::Source::GitHubTarball do
  subject(:it) { described_class.new("foo", ">= 0", "bar/puppet-foo") }

  it "can be instantiated" do
    expect(it).to_not be_nil
  end

  it "inherits Henson::Source::Generic" do
    expect(it).to be_a(Henson::Source::Generic)
  end

  describe "#name" do
    it "should return the name of the module" do
      expect(it.name).to eq("foo")
    end
  end

  describe "#repo" do
    it "should return the repository name for the module" do
      expect(it.repo).to eq("bar/puppet-foo")
    end
  end

  describe "#version" do
    it "should return the resolved version" do
      it.expects(:resolve_version_from_requirement).with(">= 0").once.returns("1.0.0")
      expect(it.version).to eq("1.0.0")
    end
  end

  describe "#fetched?" do
    it "should return true if the tarball exists on disk" do
      it.expects(:version).returns("1.0.0")
      it.send(:tarball_path).expects(:file?).returns(true)
      expect(it.fetched?).to be_true
    end

    it "should return false if the tarball does not exist" do
      it.expects(:version).returns("1.0.0")
      it.send(:tarball_path).expects(:file?).returns(false)
      expect(it.fetched?).to be_false
    end
  end

  describe "#fetch!" do
    it "should download the tarball" do
      it.send(:cache_path).expects(:mkpath)
      it.expects(:clean_up_old_cached_versions)
      it.expects(:version).returns("1.0.0").at_least(2)
      it.expects(:download_file).with(
        "https://api.github.com/repos/bar/puppet-foo/tarball/1.0.0",
        it.send(:tarball_path).to_path)
      it.fetch!
    end

    it "should append ?access_token to the URL if GITHUB_API_TOKEN envvar set" do
      it.send(:cache_path).expects(:mkpath)
      it.expects(:clean_up_old_cached_versions)
      it.expects(:version).returns("1.0.0").twice
      it.expects(:download_file).with(
        "https://api.github.com/repos/bar/puppet-foo/tarball/1.0.0?access_token=foo",
        it.send(:tarball_path).to_path)
      ENV["GITHUB_API_TOKEN"] = "foo"
      it.fetch!
      ENV.delete("GITHUB_API_TOKEN")
    end
  end
<commit_msg>Partially fix GitHubTarball specs<commit_after>require "spec_helper"

require "henson/source/github_tarball"

describe Henson::Source::GitHubTarball do
  subject(:it) { described_class.new("foo", ">= 0", "bar/puppet-foo") }

  it "can be instantiated" do
    expect(it).to_not be_nil
  end

  it "inherits Henson::Source::Generic" do
    expect(it).to be_a(Henson::Source::Generic)
  end

  describe "#name" do
    it "should return the name of the module" do
      expect(it.name).to eq("foo")
    end
  end

  describe "#repo" do
    it "should return the repository name for the module" do
      expect(it.repo).to eq("bar/puppet-foo")
    end
  end

  describe "#version" do
    it "should return the resolved version" do
      it.expects(:resolve_version_from_requirement).with(">= 0").once.returns("1.0.0")
      expect(it.version).to eq("1.0.0")
    end
  end

  describe "#fetched?" do
    it "should return true if the tarball exists on disk" do
      it.expects(:version).returns("1.0.0")
      it.send(:tarball_path).expects(:file?).returns(true)
      expect(it.fetched?).to be_true
    end

    it "should return false if the tarball does not exist" do
      it.expects(:version).returns("1.0.0")
      it.send(:tarball_path).expects(:file?).returns(false)
      expect(it.fetched?).to be_false
    end
  end

  describe "#fetch!" do
    it "should download the tarball" do
      it.send(:cache_path).expects(:mkpath)
      it.expects(:clean_up_old_cached_versions)
      it.expects(:version).returns("1.0.0").at_least(3)
      it.expects(:download_file).with(
        "https://api.github.com/repos/bar/puppet-foo/tarball/1.0.0",
        it.send(:tarball_path).to_path)
      it.fetch!
    end

    it "should append ?access_token to the URL if GITHUB_API_TOKEN envvar set" do
      it.send(:cache_path).expects(:mkpath)
      it.expects(:clean_up_old_cached_versions)
      it.expects(:version).returns("1.0.0").at_least(3)
      it.expects(:download_file).with(
        "https://api.github.com/repos/bar/puppet-foo/tarball/1.0.0?access_token=foo",
        it.send(:tarball_path).to_path)
      ENV["GITHUB_API_TOKEN"] = "foo"
      it.fetch!
      ENV.delete("GITHUB_API_TOKEN")
    end
  end

{'fraction_non_alphanumeric': 0.14259681093394078, 'fraction_numerical': 0.012528473804100227, 'mean_word_length': 3.2302504816955686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5204866', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1545, 'n_words': 307}