<commit_before># Adapter watch
#
# @param [Listen::Listener] listener the adapter listener
# @param [String] path the path to watch
#
def watch(listener, path)
  callback = lambda { |changed_dirs, options| @called = true; listener.on_change(changed_dirs, options) }
  @adapter = Listen::Adapter.select_and_initialize(path, { :latency => test_latency }, &callback)
  @adapter.start

  yield

  @adapter.wait_for_callback
ensure
  @adapter.stop
end

shared_examples_for 'an adapter that call properly listener#on_change' do |*args|
  options = (args.first && args.first.is_a?(Hash)) ? args.first : {}
  let(:listener) { mock(Listen::Listener) }
  before { described_class.stub(:work?) { true } }

  context 'single file operations' do
    context 'when a file is created' do
      it 'detects the added file' do
        fixtures do |path|
          if options[:recursive]
            listener.should_receive(:on_change).once.with([path], :recursive => true)
          else
            listener.should_receive(:on_change).once.with([path], {})
          end

          watch(listener, path) do<commit_msg>Prevent spec suite to block on Darwin<commit_after># Adapter watch
#
# @param [Listen::Listener] listener the adapter listener
# @param [String] path the path to watch
#
def watch(listener, path)
  callback = lambda { |changed_dirs, options| @called = true; listener.on_change(changed_dirs, options) }
  @adapter = Listen::Adapter.select_and_initialize(path, { :latency => test_latency }, &callback)
  @adapter.start

  yield

  @adapter.wait_for_callback
ensure
  # Prevent spec suite to block on Darwin when stopping adapter
  @adapter.stop unless @adapter.is_a?(Listen::Adapters::Darwin)
end

shared_examples_for 'an adapter that call properly listener#on_change' do |*args|
  options = (args.first && args.first.is_a?(Hash)) ? args.first : {}
  let(:listener) { mock(Listen::Listener) }
  before { described_class.stub(:work?) { true } }

  context 'single file operations' do
    context 'when a file is created' do
      it 'detects the added file' do
        fixtures do |path|
          if options[:recursive]
            listener.should_receive(:on_change).once.with([path], :recursive => true)
          else
            listener.should_receive(:on_change).once.with([path], {})
          end

          watch(listener, path) do
{'fraction_non_alphanumeric': 0.1188034188034188, 'fraction_numerical': 0.0, 'mean_word_length': 3.7484787018255576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5754154', 'n_tokens_mistral': 708, 'n_tokens_neox': 693, 'n_words': 193}