<commit_before>require 'spec_helper'

require 'method_log/repository'
require 'method_log/commit'
require 'method_log/source_file'

module MethodLog
  describe Commit do
    let(:sha) { 'b54d38bbd989f4b54c38fd77767d89d1' }
    let(:commit) { Commit.new(sha: sha) }
    let(:commit_with_same_sha) { Commit.new(sha: sha) }

    it 'is equal to another commit with same SHA' do
      expect(commit).to eq(commit_with_same_sha)
    end

    it 'has same hash as another commit with same SHA' do
      expect(commit.hash).to eq(commit_with_same_sha.hash)
    end

    context 'using a real git repository' do
      let(:repository_path) { File.expand_path('../repository.git', __FILE__) }

      before do
        FileUtils.mkdir_p(repository_path)
        Rugged::Repository.init_at(repository_path, :bare)
      end

      after do
        FileUtils.rm_rf(repository_path)
      end

      it 'stores source files added to a commit in the repository against a real commit' do
        source_one = source(path: 'path/to/source_one.rb', source: 'source-one')
        source_two = source(path: 'path/to/source_two.rb', source: 'source-two')

        repository = Repository.new(path: repository_path)
        commit = repository.commit(source_one, source_two)

        repository = Repository.new(path: repository_path)
        commit = repository.commits.first
        expect(commit.source_files.to_a).to eq([source_one, source_two])
      end

      it 'only includes source files with ruby file extension' do
        source_file = source(path: 'path/to/source_one.py', source: 'source-file')

        repository = Repository.new(path: repository_path)
        commit = repository.commit(source_file)

        repository = Repository.new(path: repository_path)
        commit = repository.commits.first
        expect(commit.source_files.to_a).to be_empty
      end

      it 'indicates whether it contains a given source file' do
        source_file = source(path: 'path/to/source.rb', source: 'source-file')

        repository = Repository.new(path: repository_path)
        commit = repository.commit(source_file)
        source_file = commit.source_files.first

        repository = Repository.new(path: repository_path)
        commit = repository.commits.first
        expect(commit.contains?(source_file)).to be_true<commit_msg>Improve test coverage for Commit#contains?<commit_after>require 'spec_helper'

require 'method_log/repository'
require 'method_log/commit'
require 'method_log/source_file'

module MethodLog
  describe Commit do
    let(:sha) { 'b54d38bbd989f4b54c38fd77767d89d1' }
    let(:commit) { Commit.new(sha: sha) }
    let(:commit_with_same_sha) { Commit.new(sha: sha) }

    it 'is equal to another commit with same SHA' do
      expect(commit).to eq(commit_with_same_sha)
    end

    it 'has same hash as another commit with same SHA' do
      expect(commit.hash).to eq(commit_with_same_sha.hash)
    end

    context 'using a real git repository' do
      let(:repository_path) { File.expand_path('../repository.git', __FILE__) }

      before do
        FileUtils.mkdir_p(repository_path)
        Rugged::Repository.init_at(repository_path, :bare)
      end

      after do
        FileUtils.rm_rf(repository_path)
      end

      it 'stores source files added to a commit in the repository against a real commit' do
        source_one = source(path: 'path/to/source_one.rb', source: 'source-one')
        source_two = source(path: 'path/to/source_two.rb', source: 'source-two')

        repository = Repository.new(path: repository_path)
        commit = repository.commit(source_one, source_two)

        repository = Repository.new(path: repository_path)
        commit = repository.commits.first
        expect(commit.source_files.to_a).to eq([source_one, source_two])
      end

      it 'only includes source files with ruby file extension' do
        source_file = source(path: 'path/to/source_one.py', source: 'source-file')

        repository = Repository.new(path: repository_path)
        commit = repository.commit(source_file)

        repository = Repository.new(path: repository_path)
        commit = repository.commits.first
        expect(commit.source_files.to_a).to be_empty
      end

      it 'indicates whether it contains a given source file' do
        source_file = source(path: 'path/to/source.rb', source: 'source-file')
        another_source_file = source(path: 'path/to/another_source.rb', source: 'another-source-file')

        repository = Repository.new(path: repository_path)
        commit = repository.commit(source_file)
        source_file = commit.source_files.first
        another_commit = repository.commit(another_source_file)
        another_source_file = another_commit.source_files.first

        repository = Repository.new(path: repository_path)
        commit = repository.commits.to_a.last

        expect(commit.contains?(source_file)).to be_true
        expect(commit.contains?(another_source_file)).to be_false
{'fraction_non_alphanumeric': 0.0960960960960961, 'fraction_numerical': 0.008008008008008008, 'mean_word_length': 3.2664389410760033, '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': '5789442', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1472, 'n_words': 346}