<commit_before>require 'spec_helper'
require 'fileutils'
require 'guard/listeners/linux'

describe Guard::Linux do

  if mac?
    it "isn't usable on 10.6" do
      described_class.should_not be_usable
    end
  end

  if windows?
    it "isn't usable on windows" do
      described_class.should_not be_usable
    end
  end

  if linux? && Guard::Linux.usable?
    it "is usable on linux" do
      described_class.should be_usable
    end

    describe "#start", :long_running => true do
      before(:each) do
        @listener = Guard::Linux.new
      end

      it "calls watch_change on the first start" do
        @listener.should_receive(:watch_change)
        start
      end

      it "doesn't call watch_change on subsequent starts after a stop" do
        @listener.stub!(:stop)
        start
        stop
        @listener.should be_watch_change
        @listener.should_not_receive(:watch_change)
        start
        @listener.unstub!(:stop)
        stop
        sleep 1
        @listener.should_not be_watch_change
      end
    end

    it_should_behave_like "a listener that reacts to #on_change"
    it_should_behave_like "a listener scoped to a specific directory"

    # Fun fact: FileUtils.touch seems not to be enough on Linux to trigger a modify event

    it "catches modified files with glib saving routine (like Vim, Emacs or Gedit)" do
      @listener = described_class.new
      record_results
      file = @fixture_path.join("folder1/file1.txt")
      File.exists?(file).should be_true
      start
      File.open(file, 'r+').close
      FileUtils.touch(file)
      stop
      results.should =~ ['spec/fixtures/folder1/file1.txt']
    end
<commit_msg>Stub inotify.process for control flow test.<commit_after>require 'spec_helper'
require 'fileutils'
require 'guard/listeners/linux'

describe Guard::Linux do

  if mac?
    it "isn't usable on 10.6" do
      described_class.should_not be_usable
    end
  end

  if windows?
    it "isn't usable on windows" do
      described_class.should_not be_usable
    end
  end

  if linux? && Guard::Linux.usable?
    it "is usable on linux" do
      described_class.should be_usable
    end

    describe "#start", :long_running => true do
      before(:each) do
        @listener = Guard::Linux.new
        @listener.instance_variable_get(:@inotify).stub(:process)
      end

      it "calls watch_change on the first start" do
        @listener.should_receive(:watch_change)
        start
      end

      it "doesn't call watch_change on subsequent starts after a stop" do
        @listener.stub!(:stop)
        start
        stop
        @listener.should be_watch_change
        @listener.should_not_receive(:watch_change)
        start
        @listener.unstub!(:stop)
        stop
        @listener.should_not be_watch_change
      end
    end

    it_should_behave_like "a listener that reacts to #on_change"
    it_should_behave_like "a listener scoped to a specific directory"

    # Fun fact: FileUtils.touch seems not to be enough on Linux to trigger a modify event

    it "catches modified files with glib saving routine (like Vim, Emacs or Gedit)" do
      @listener = described_class.new
      record_results
      file = @fixture_path.join("folder1/file1.txt")
      File.exists?(file).should be_true
      start
      File.open(file, 'r+').close
      FileUtils.touch(file)
      stop
      results.should =~ ['spec/fixtures/folder1/file1.txt']
    end

{'fraction_non_alphanumeric': 0.08023255813953488, 'fraction_numerical': 0.00436046511627907, 'mean_word_length': 2.6182965299684544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7201805', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1031, 'n_words': 306}