<commit_before>require 'spec_helper'

describe Eye do
  before(:each) do
    # We don't want to locked in a loop
    $close_eye = true

    # Set the project's name and path
    @file_path = '/home/user/Code/OpenSource/watch_tower/lib/watch_tower/server/models/time_entries.rb'
    @project_path = '/home/user/Code/OpenSource/watch_tower'
    @project_name = 'watch_tower'

    # Mock the editor
    @editor = mock
    @editor.stubs(:new).returns(@editor)
    @editor.stubs(:is_running?).returns(true)
    @editor.stubs(:current_paths).returns([@file_path])
    Editor.stubs(:editors).returns([@editor])

    # Mock the project
    @project = mock
    @project.stubs(:path).returns(@project_path)
    @project.stubs(:name).returns(@project_name)
    Project.stubs(:new_from_path).returns(@project)

    # Stub the mtime
    @mtime = Time.now
    @file_stat = mock
    @file_stat.stubs(:mtime).returns(@mtime)
    ::File.stubs(:stat).returns(@file_stat)
  end

  describe "#start totally mocked" do
    before(:each) do
      # Mock the project's model
      # @time_entry = stub_everything('time_entry')
      # @file_model = stub_everything('file', time_entries: [@time_entries])
      # @project_model = stub_everything('project', files: [@file_model])
      # Server::Project.stubs(:find_or_create_by_name_and_path).returns(@project_model)
    end

    it { should respond_to :start }

    it "should tries to get the editors list" do
      Editor.expects(:editors).returns([]).once

      subject.start
    end

    it "should call is_running? on the editor" do
      @editor.expects(:is_running?).returns(false).once
      Editor.stubs(:editors).returns([@editor])

      subject.start
    end

    it "should call current_paths on the editor to determine the file path" do
      @editor.expects(:current_paths).returns([@file_path]).once

      subject.start
    end

    it "should create a new project from the file path" do
      Project.expects(:new_from_path).returns(@project).once

      subject.start
    end

    it "should ask the project for the project's name" do
      @project.expects(:name).returns(@project_name).once

      subject.start
    end

    it "should ask the project for the project's path" do
      @project.expects(:path).returns(@project_path).once

      subject.start
    end

    it "should create a new (or fetch existing) Project in the database"
    it "should create a new (or fetch existing) File in the database"
    it "should create a new TimeEntry in the database"

    it "should ask the file for mtime" do
      @file_stat.expects(:mtime).returns(Time.now).once
      ::File.expects(:stat).with(@file_path).returns(@file_stat)

      subject.start
    end
  end

  describe "#start database validations" do
    it "should create a new (or fetch existing) Project in the database" do
      subject.start

      Server::Project.last.name.should == @project_name
      Server::Project.last.path.should == @project_path
    end

    it "should create a new (or fetch existing) File in the database" do
      subject.start

      Server::File.last.path.should == @file_path
    end

    it "should create a new TimeEntry in the database" # do
     #      subject.start
     #
     #      Server::TimeEntry.last.mtime.should == @mtime
     #    end

    it "should not raise an error if the time entry for the file already exists" do
      subject.start

      -> { subject.start }.should_not raise_error
    end
  end
end<commit_msg>Revert "Eye: This test is breaking Travis-ci tests, I don't know why because it is working on my environment, leave it pending."<commit_after>require 'spec_helper'

describe Eye do
  before(:each) do
    # We don't want to locked in a loop
    $close_eye = true

    # Set the project's name and path
    @file_path = '/home/user/Code/OpenSource/watch_tower/lib/watch_tower/server/models/time_entries.rb'
    @project_path = '/home/user/Code/OpenSource/watch_tower'
    @project_name = 'watch_tower'

    # Mock the editor
    @editor = mock
    @editor.stubs(:new).returns(@editor)
    @editor.stubs(:is_running?).returns(true)
    @editor.stubs(:current_paths).returns([@file_path])
    Editor.stubs(:editors).returns([@editor])

    # Mock the project
    @project = mock
    @project.stubs(:path).returns(@project_path)
    @project.stubs(:name).returns(@project_name)
    Project.stubs(:new_from_path).returns(@project)

    # Stub the mtime
    @mtime = Time.now
    @file_stat = mock
    @file_stat.stubs(:mtime).returns(@mtime)
    ::File.stubs(:stat).returns(@file_stat)
  end

  describe "#start totally mocked" do
    before(:each) do
      # Mock the project's model
      # @time_entry = stub_everything('time_entry')
      # @file_model = stub_everything('file', time_entries: [@time_entries])
      # @project_model = stub_everything('project', files: [@file_model])
      # Server::Project.stubs(:find_or_create_by_name_and_path).returns(@project_model)
    end

    it { should respond_to :start }

    it "should tries to get the editors list" do
      Editor.expects(:editors).returns([]).once

      subject.start
    end

    it "should call is_running? on the editor" do
      @editor.expects(:is_running?).returns(false).once
      Editor.stubs(:editors).returns([@editor])

      subject.start
    end

    it "should call current_paths on the editor to determine the file path" do
      @editor.expects(:current_paths).returns([@file_path]).once

      subject.start
    end

    it "should create a new project from the file path" do
      Project.expects(:new_from_path).returns(@project).once

      subject.start
    end

    it "should ask the project for the project's name" do
      @project.expects(:name).returns(@project_name).once

      subject.start
    end

    it "should ask the project for the project's path" do
      @project.expects(:path).returns(@project_path).once

      subject.start
    end

    it "should create a new (or fetch existing) Project in the database"
    it "should create a new (or fetch existing) File in the database"
    it "should create a new TimeEntry in the database"

    it "should ask the file for mtime" do
      @file_stat.expects(:mtime).returns(Time.now).once
      ::File.expects(:stat).with(@file_path).returns(@file_stat)

      subject.start
    end
  end

  describe "#start database validations" do
    it "should create a new (or fetch existing) Project in the database" do
      subject.start

      Server::Project.last.name.should == @project_name
      Server::Project.last.path.should == @project_path
    end

    it "should create a new (or fetch existing) File in the database" do
      subject.start

      Server::File.last.path.should == @file_path
    end

    it "should create a new TimeEntry in the database" do
      subject.start

      Server::TimeEntry.last.mtime.should == @mtime
    end

    it "should not raise an error if the time entry for the file already exists" do
      subject.start

      -> { subject.start }.should_not raise_error
    end
  end
end
{'fraction_non_alphanumeric': 0.10884064140769122, 'fraction_numerical': 0.0, 'mean_word_length': 3.14832254267216, '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': '5259256', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2105, 'n_words': 594}