<commit_before>require 'yaml/store'
require_relative '../spec_helper'
require_relative '../../lib/signore/sig_finder'
require_relative '../../lib/signore/tags'

module Signore
  describe SigFinder do
    let(:sigs) do
      store = YAML::Store.new('spec/fixtures/signatures.yml')
      store.transaction(true) { store['signatures'] }.map do |hash|
        Signature.from_h(hash)
      end
    end

    let(:sig_finder) { SigFinder.new(sigs) }

    describe '.find' do
      it 'returns a random Signature by default' do
        SigFinder.find(sigs, random: Random.new(1981)).text
          .must_include 'Amateur fighter pilot ignores orders'
        SigFinder.find(sigs, random: Random.new(2009)).text
          .must_equal '// sometimes I believe compiler ignores all my comments'
      end

      it 'returns a random signature if the tags are empty' do
        SigFinder.find(sigs, tags: Tags.new, random: Random.new(2013)).text
          .must_equal '// sometimes I believe compiler ignores all my comments'
      end

      it 'returns a random signature based on provided tags' do
        SigFinder.find(sigs, tags: Tags.new(required: %w(programming))).text
          .must_equal '// sometimes I believe compiler ignores all my comments'
        SigFinder.find(sigs, tags: Tags.new(required: %w(work))).text
          .must_equal 'You do have to be mad to work here, but it doesn’t help.'
      end

      it 'returns a random signature based on required and forbidden tags' do
        tags = Tags.new(forbidden: %w(programming security), required: %w(tech))
        SigFinder.find(sigs, tags: tags).text
          .must_equal 'You do have to be mad to work here, but it doesn’t help.'
      end

      it 'returns a null object if there are no results' do<commit_msg>SigFinder spec: refactor a bit<commit_after>require 'yaml/store'
require_relative '../spec_helper'
require_relative '../../lib/signore/sig_finder'
require_relative '../../lib/signore/tags'

module Signore
  describe SigFinder do
    let(:sigs) do
      Database.new(path: Pathname.new('spec/fixtures/signatures.yml')).sigs
    end

    let(:sig_finder) { SigFinder.new(sigs) }

    describe '.find' do
      it 'returns a random Signature by default' do
        SigFinder.find(sigs, random: Random.new(1981)).text
          .must_include 'Amateur fighter pilot ignores orders'
        SigFinder.find(sigs, random: Random.new(2009)).text
          .must_equal '// sometimes I believe compiler ignores all my comments'
      end

      it 'returns a random signature if the tags are empty' do
        SigFinder.find(sigs, tags: Tags.new, random: Random.new(2013)).text
          .must_equal '// sometimes I believe compiler ignores all my comments'
      end

      it 'returns a random signature based on provided tags' do
        SigFinder.find(sigs, tags: Tags.new(required: %w(programming))).text
          .must_equal '// sometimes I believe compiler ignores all my comments'
        SigFinder.find(sigs, tags: Tags.new(required: %w(work))).text
          .must_equal 'You do have to be mad to work here, but it doesn’t help.'
      end

      it 'returns a random signature based on required and forbidden tags' do
        tags = Tags.new(forbidden: %w(programming security), required: %w(tech))
        SigFinder.find(sigs, tags: tags).text
          .must_equal 'You do have to be mad to work here, but it doesn’t help.'
      end

      it 'returns a null object if there are no results' do
{'fraction_non_alphanumeric': 0.10368663594470046, 'fraction_numerical': 0.0069124423963133645, 'mean_word_length': 2.8375690607734807, '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': '1761315', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1005, 'n_words': 346}