<commit_before>require 'spec_helper'

describe Guard::Listener do
  subject { Guard::Listener }

  describe ".select_and_init" do
    before(:each) { @target_os = Config::CONFIG['target_os'] }
    after(:each) { Config::CONFIG['target_os'] = @target_os }

    it "uses darwin listener on Mac OS X" do
      Config::CONFIG['target_os'] = 'darwin10.4.0'
      Guard::Darwin.stub(:usable?).and_return(true)
      Guard::Darwin.should_receive(:new)
      subject.select_and_init
    end

    it "uses windows listener on Windows" do
      Config::CONFIG['target_os'] = 'mingw'
      Guard::Windows.stub(:usable?).and_return(true)
      Guard::Windows.should_receive(:new)
      subject.select_and_init
    end

    it "uses linux listener on Linux" do
      Config::CONFIG['target_os'] = 'linux'
      Guard::Linux.stub(:usable?).and_return(true)
      Guard::Linux.should_receive(:new)
      subject.select_and_init
    end
  end

  describe "#update_last_event" do
    subject { described_class.new }

    it "updates last_event with time.now" do
      time = Time.now
      subject.update_last_event
      subject.last_event.to_i.should >= time.to_i
    end

  end

end<commit_msg>Add missing specs for file modification detection (See SHA: 0dcf13d77c57c53bc8b7b52533687e1f726fc171)<commit_after>require 'spec_helper'

describe Guard::Listener do
  subject { Guard::Listener }

  describe ".select_and_init" do
    before(:each) { @target_os = Config::CONFIG['target_os'] }
    after(:each) { Config::CONFIG['target_os'] = @target_os }

    it "uses darwin listener on Mac OS X" do
      Config::CONFIG['target_os'] = 'darwin10.4.0'
      Guard::Darwin.stub(:usable?).and_return(true)
      Guard::Darwin.should_receive(:new)
      subject.select_and_init
    end

    it "uses windows listener on Windows" do
      Config::CONFIG['target_os'] = 'mingw'
      Guard::Windows.stub(:usable?).and_return(true)
      Guard::Windows.should_receive(:new)
      subject.select_and_init
    end

    it "uses linux listener on Linux" do
      Config::CONFIG['target_os'] = 'linux'
      Guard::Linux.stub(:usable?).and_return(true)
      Guard::Linux.should_receive(:new)
      subject.select_and_init
    end
  end

  describe "#update_last_event" do
    subject { described_class.new }

    it "updates last_event with time.now" do
      time = Time.now
      subject.update_last_event
      subject.last_event.to_i.should >= time.to_i
    end
  end

  describe "#modified_files" do
    subject { described_class.new }

    let(:file1) { File.new(@fixture_path.join("folder1", "file1.txt")) }
    let(:file2) { File.new(@fixture_path.join("folder1", "folder2", "file2.txt")) }
    let(:file3) { File.new(@fixture_path.join("folder1", "deletedfile1.txt")) }

    before do
      subject.update_last_event
      sleep 0.56
    end

    context "without the :all option" do
      it "finds modified files only in the directory supplied" do
        FileUtils.touch([file1, file2, file3])
        subject.modified_files([@fixture_path.join("folder1/")], {}).should eql ["spec/fixtures/folder1/deletedfile1.txt", "spec/fixtures/folder1/file1.txt"]
      end
    end

    context "with the :all options" do
      it "finds modified files within subdirectories" do
        FileUtils.touch([file1, file2, file3])
        subject.modified_files([@fixture_path.join("folder1/")], { :all => true }).should eql ["spec/fixtures/folder1/deletedfile1.txt", "spec/fixtures/folder1/file1.txt", "spec/fixtures/folder1/folder2/file2.txt"]
      end
    end

    context "without updating the content" do
      it "ignores the files for the second time" do
        FileUtils.touch([file1, file2, file3])
        subject.modified_files([@fixture_path.join("folder1/")], {}).should eql ["spec/fixtures/folder1/deletedfile1.txt", "spec/fixtures/folder1/file1.txt"]
        sleep 0.6
        FileUtils.touch([file1, file2, file3])
        subject.modified_files([@fixture_path.join("folder1/")], {}).should eql []
      end
    end

    context "with content that has changed" do
      after { File.open(file1, "w") { |f| f.write('') } }

      it "identifies the files for the second time" do
        FileUtils.touch([file1, file2, file3])
        subject.modified_files([@fixture_path.join("folder1/")], {}).should eql ["spec/fixtures/folder1/deletedfile1.txt", "spec/fixtures/folder1/file1.txt"]
        sleep 0.6
        FileUtils.touch([file2, file3])
        File.open(file1, "w") { |f| f.write('changed content') }
        subject.modified_files([@fixture_path.join("folder1/")], {}).should eql ["spec/fixtures/folder1/file1.txt"]
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.13508847647820457, 'fraction_numerical': 0.020932239965472593, 'mean_word_length': 3.3975332068311195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '331247', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1511, 'n_words': 313}