<commit_before>require 'machinegun'

describe MachineGun do
  
  # Prevent the test suite process from forking.
  def stub_fork
    allow(subject).to receive(:fork) { |&block| block.call; pid }
    
    allow(Process).to receive(:kill)
    allow(Process).to receive(:wait)
  end
  
  # Prevent the rack server from running.
  def stub_rack_server opts = {}
    called = opts.fetch :called, :once
    ignore = opts.fetch :ignore, false
    
    if ignore
      allow(Rack::Server).to receive(:start)
    else
      Rack::Server.should_receive(:start).at_least(called)
    end
  end
  
  # Prevent FileWatcher from monitoring the file system.
  def stub_file_watcher opts = {}
    run_block = opts.fetch :run_block, false
    ignore = opts.fetch :ignore, false
    
    _interval = (respond_to?(:interval) ? interval : nil) || 0.5
    
    if ignore
      allow(FileWatcher).to receive(:new) {
        double(FileWatcher).tap do |d|
          allow(d).to receive(:watch)
          allow(d).to receive(:stop)
        end
      }
    else
      FileWatcher.should_receive(:new).at_least(:once) {
        double(FileWatcher).tap do |d|
          allow(d).to receive(:stop)
          
          d.should_receive(:watch).with(_interval).at_least(:once) { |&block|
            block.call if run_block
          }
        end
      }
    end
  end
  
  let(:pid) { 0 } # PID 0 can't be killed if Process.kill is accidentally called.
  
  let(:rack_server_start_called) { :once }
  let(:ignore_rack_server) { false }
  let(:rack_stub_opts) {{
    ignore: ignore_rack_server,
    called: rack_server_start_called,
  }}
  
  let(:ignore_file_watcher) { false }
  let(:run_file_watcher_block) { false }
  let(:file_watcher_opts) {{
    ignore: ignore_file_watcher,
    run_block: run_file_watcher_block,
  }}
  
  before {
    stub_fork
    stub_rack_server **rack_stub_opts
    stub_file_watcher **file_watcher_opts
  }
  
  describe "class" do
    subject { MachineGun }
    let(:ignore_rack_server) { true }
    let(:ignore_file_watcher) { true }
    
    specify { subject.run }
  end<commit_msg>Removed splatted opts for 1.9.3 compatibility.<commit_after>require 'machinegun'

describe MachineGun do
  
  # Prevent the test suite process from forking.
  def stub_fork
    allow(subject).to receive(:fork) { |&block| block.call; pid }
    
    allow(Process).to receive(:kill)
    allow(Process).to receive(:wait)
  end
  
  # Prevent the rack server from running.
  def stub_rack_server opts = {}
    called = opts.fetch :called, :once
    ignore = opts.fetch :ignore, false
    
    if ignore
      allow(Rack::Server).to receive(:start)
    else
      Rack::Server.should_receive(:start).at_least(called)
    end
  end
  
  # Prevent FileWatcher from monitoring the file system.
  def stub_file_watcher opts = {}
    run_block = opts.fetch :run_block, false
    ignore = opts.fetch :ignore, false
    
    _interval = (respond_to?(:interval) ? interval : nil) || 0.5
    
    if ignore
      allow(FileWatcher).to receive(:new) {
        double(FileWatcher).tap do |d|
          allow(d).to receive(:watch)
          allow(d).to receive(:stop)
        end
      }
    else
      FileWatcher.should_receive(:new).at_least(:once) {
        double(FileWatcher).tap do |d|
          allow(d).to receive(:stop)
          
          d.should_receive(:watch).with(_interval).at_least(:once) { |&block|
            block.call if run_block
          }
        end
      }
    end
  end
  
  let(:pid) { 0 } # PID 0 can't be killed if Process.kill is accidentally called.
  
  let(:rack_server_start_called) { :once }
  let(:ignore_rack_server) { false }
  let(:rack_stub_opts) {{
    ignore: ignore_rack_server,
    called: rack_server_start_called,
  }}
  
  let(:ignore_file_watcher) { false }
  let(:run_file_watcher_block) { false }
  let(:file_watcher_opts) {{
    ignore: ignore_file_watcher,
    run_block: run_file_watcher_block,
  }}
  
  before {
    stub_fork
    stub_rack_server rack_stub_opts
    stub_file_watcher file_watcher_opts
  }
  
  describe "class" do
    subject { MachineGun }
    let(:ignore_rack_server) { true }
    let(:ignore_file_watcher) { true }
    
    specify { subject.run }
  end
{'fraction_non_alphanumeric': 0.1073043064477754, 'fraction_numerical': 0.0026171782060433026, 'mean_word_length': 2.7302573203194322, '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': '5796290', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1385, 'n_words': 298}