<commit_before>=begin
Copyright 2014 <NAME> <<EMAIL>>

See the file LICENSE for copying permission.
=end

require "test_helper"
require "context-filters/context"

describe GemContent do

  subject do
    GemContent.new("some-templates")
  end

  let(:gems_all) do
    Gem::Specification._all
  end

  let(:gems_one) do
    gems_all.select{|s| s.name == "fake-gem-name-one"}
  end

  let(:gems_one_expected) do
    gems_one.select{|s| s.metadata && s.metadata["some-templates"] }
  end

  let(:gems_two) do
    gems_all.select{|s| s.name == "fake-gem-name-two"}
  end

  before do
    gems_two.find{ |s| s.version == Gem::Version.new("1.0.0") }.activate
  end

  it "initializes content_name" do
    subject.content_name.must_equal("some-templates")
  end

  it "detects gems" do
    subject.expects(:all_gems).returns(gems_one)
    subject.send(:all_gems_matching).sort.must_equal(gems_one_expected.sort)
  end

  it "finds latest gems" do
    subject.expects(:all_gems_matching).returns(gems_one_expected)
    subject.send(:active_or_latest_gems_matching).must_equal([gems_one_expected.sort.last])
  end

  it "finds latest gem from list" do
    subject.send(:active_or_latest_gem, ["fake-gem-name-one", gems_one_expected]).must_equal(gems_one_expected.sort.last)
  end

  it "finds active gems" do
    subject.expects(:all_gems_matching).returns(gems_two)
    subject.send(:active_or_latest_gems_matching).must_equal([gems_two.sort.first])
  end

  it "finds active gem on list" do
    subject.send(:active_or_latest_gem, ["fake-gem-name-two", gems_two]).must_equal(gems_two.sort.first)
  end

  it "returns gems paths" do
    subject.expects(:active_or_latest_gems_matching).returns(gems_one_expected.sort)
    subject.get_gem_paths.must_equal(
      [
        File.expand_path("../gems/gems/fake-gem-name-one-1.0.0/templates-v1", __FILE__),
        File.expand_path("../gems/gems/fake-gem-name-one-2.0.0/templates-v2", __FILE__),
      ]
    )
  end

  it "returns gems paths - no mocking - the real test" do
    subject.get_gem_paths.must_equal(
      [
        File.expand_path("../gems/gems/fake-gem-name-one-2.0.0/templates-v2", __FILE__),
        File.expand_path("../gems/gems/fake-gem-name-two-1.0.0/templates-v1", __FILE__),
      ]
    )
  end

  it "has class helper" do
    test_subject = mock()
    test_subject.expects(:get_gem_paths).once.returns([:a, :b])
    GemContent.expects(:new).once.with("some-templates").returns(test_subject)

    GemContent.get_gem_paths("some-templates").must_equal([:a, :b])
  end

end
<commit_msg>require proper path in tests<commit_after>=begin
Copyright 2014 <NAME> <<EMAIL>>

See the file LICENSE for copying permission.
=end

require "test_helper"
require "gem-content"

describe GemContent do

  subject do
    GemContent.new("some-templates")
  end

  let(:gems_all) do
    Gem::Specification._all
  end

  let(:gems_one) do
    gems_all.select{|s| s.name == "fake-gem-name-one"}
  end

  let(:gems_one_expected) do
    gems_one.select{|s| s.metadata && s.metadata["some-templates"] }
  end

  let(:gems_two) do
    gems_all.select{|s| s.name == "fake-gem-name-two"}
  end

  before do
    gems_two.find{ |s| s.version == Gem::Version.new("1.0.0") }.activate
  end

  it "initializes content_name" do
    subject.content_name.must_equal("some-templates")
  end

  it "detects gems" do
    subject.expects(:all_gems).returns(gems_one)
    subject.send(:all_gems_matching).sort.must_equal(gems_one_expected.sort)
  end

  it "finds latest gems" do
    subject.expects(:all_gems_matching).returns(gems_one_expected)
    subject.send(:active_or_latest_gems_matching).must_equal([gems_one_expected.sort.last])
  end

  it "finds latest gem from list" do
    subject.send(:active_or_latest_gem, ["fake-gem-name-one", gems_one_expected]).must_equal(gems_one_expected.sort.last)
  end

  it "finds active gems" do
    subject.expects(:all_gems_matching).returns(gems_two)
    subject.send(:active_or_latest_gems_matching).must_equal([gems_two.sort.first])
  end

  it "finds active gem on list" do
    subject.send(:active_or_latest_gem, ["fake-gem-name-two", gems_two]).must_equal(gems_two.sort.first)
  end

  it "returns gems paths" do
    subject.expects(:active_or_latest_gems_matching).returns(gems_one_expected.sort)
    subject.get_gem_paths.must_equal(
      [
        File.expand_path("../gems/gems/fake-gem-name-one-1.0.0/templates-v1", __FILE__),
        File.expand_path("../gems/gems/fake-gem-name-one-2.0.0/templates-v2", __FILE__),
      ]
    )
  end

  it "returns gems paths - no mocking - the real test" do
    subject.get_gem_paths.must_equal(
      [
        File.expand_path("../gems/gems/fake-gem-name-one-2.0.0/templates-v2", __FILE__),
        File.expand_path("../gems/gems/fake-gem-name-two-1.0.0/templates-v1", __FILE__),
      ]
    )
  end

  it "has class helper" do
    test_subject = mock()
    test_subject.expects(:get_gem_paths).once.returns([:a, :b])
    GemContent.expects(:new).once.with("some-templates").returns(test_subject)

    GemContent.get_gem_paths("some-templates").must_equal([:a, :b])
  end

end

{'fraction_non_alphanumeric': 0.1395485770363101, 'fraction_numerical': 0.009028459273797841, 'mean_word_length': 3.789473684210526, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4005472', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1818, 'n_words': 298}