<commit_before>require_relative '../../libraries/primitive_ensure_choregraphie'

describe Choregraphie::EnsureChoregraphie do
  let(:choregraphie) do
    Choregraphie::Choregraphie.new('test') do
      on 'test[name]'
      ensure_choregraphie 'random', period: 0.01
    end
  end
  before(:each) do
    expect_any_instance_of(Choregraphie::Choregraphie).to receive(:ruby_block)
  end

  it 'must check file if resource is not protected' do
    expect(Choregraphie::Choregraphie).to receive(:all).and_return(
      [
        double(name: 'toto', resources: ['toto[name]'])
      ],
    )
    expect(File).to receive(:exist?).with('random').and_return(true)
    choregraphie.before.each { |block| block.call 'test[name]' }
  end
  it 'must not check file if resource is protected' do
    expect(Choregraphie::Choregraphie).to receive(:all).and_return(
      [
        double(name: 'test', resources: ['test[name]']),
        double(name: 'toto', resources: ['toto[name]'])
      ],
    )
    expect(File).to_not receive(:exist?).with('random')
    choregraphie.before.each { |block| block.call 'test[name]' }
  end
  it 'must clean the file in cleanup' do
    expect(File).to receive(:exist?).and_return(true)
    expect(FileUtils).to receive(:rm).with('random')
    choregraphie.cleanup.each(&:call)
  end
end<commit_msg>Refactor tests prior modification<commit_after>require_relative '../../libraries/primitive_ensure_choregraphie'

describe Choregraphie::EnsureChoregraphie do
  let(:choregraphie) do
    Choregraphie::Choregraphie.new('test') do
      on 'my_resource_to_protect[name]'
      ensure_choregraphie 'random', period: 0.01
    end
  end
  before(:each) do
    expect_any_instance_of(Choregraphie::Choregraphie).to receive(:ruby_block)
  end

  it 'must check file if resource is not protected by another choregraphie' do
    expect(Choregraphie::Choregraphie).to receive(:all).and_return(
      [
        choregraphie,
        double(name: 'toto', resources: ['another_unrelated_resource[name]']),
      ],
    )
    expect(File).to receive(:exist?).with('random').and_return(true)
    choregraphie.before.each { |block| block.call 'my_resource_to_protect[name]' }
  end

  it 'must not check file if resource is protected' do
    expect(Choregraphie::Choregraphie).to receive(:all).and_return(
      [
        choregraphie,
        double(name: 'toto', resources: ['my_resource_to_protect[name]']),
      ],
    )
    expect(File).to_not receive(:exist?).with('random')
    choregraphie.before.each { |block| block.call 'my_resource_to_protect[name]' }
  end

  it 'must clean the file in cleanup' do
    expect(File).to receive(:exist?).and_return(true)
    expect(FileUtils).to receive(:rm).with('random')
    choregraphie.cleanup.each(&:call)
  end
end
{'fraction_non_alphanumeric': 0.13641284734752795, 'fraction_numerical': 0.0021652832912306026, 'mean_word_length': 4.086238532110092, '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': '6073508', 'n_tokens_mistral': 937, 'n_tokens_neox': 910, 'n_words': 177}