<commit_before>require 'spec_helper'
require 'net/ftp'

describe FakeFtp::Server, 'with ftp client' do
  let(:server) { FakeFtp::Server.new(21212, 21213) }
  let(:client) { Net::FTP.new }
  let(:text_filename) { File.expand_path("../fixtures/text_file.txt", File.dirname(__FILE__)) }

  before { server.start }

  after :each do
    client.close
    server.stop
  end

  it 'should accept connections' do
    expect { client.connect('127.0.0.1', 21212) }.to_not raise_error
  end

  context "with client" do
    before { client.connect("127.0.0.1", 21212) }

    it "should allow anonymous authentication" do
      expect { client.login }.to_not raise_error
    end

    it "should allow named authentication" do
      expect { client.login('someone', 'password') }.to_not raise_error
    end

    it "should allow client to quit" do
      expect { client.login('someone', 'password') }.to_not raise_error
      expect { client.quit }.to_not raise_error
    end

    it "should allow mtime" do
      filename = 'someone'
      time = Time.now
      server.add_file(filename, "some data", time)

      client.passive = false
      mtime = client.mtime(filename)
      expect(mtime.to_s).to eql(time.to_s)

      client.passive = true
      mtime = client.mtime(filename)
      expect(mtime.to_s).to eql(time.to_s)
    end

    it "should put files using PASV" do
      expect(File.stat(text_filename).size).to eql(20)

      client.passive = true
      expect { client.put(text_filename) }.to_not raise_error

      expect(server.files).to include('text_file.txt')
      expect(server.file('text_file.txt').bytes).to eql(20)
      expect(server.file('text_file.txt')).to be_passive
      expect(server.file('text_file.txt')).to_not be_active
    end

    it "should put files using active" do
      expect(File.stat(text_filename).size).to eql(20)

      client.passive = false
      expect { client.put(text_filename) }.to_not raise_error

      expect(server.files).to include('text_file.txt')
      expect(server.file('text_file.txt').bytes).to eql(20)
      expect(server.file('text_file.txt')).to_not be_passive
      expect(server.file('text_file.txt')).to be_active
    end

    xit "should disconnect clients on close" do
      # TODO: when this succeeds, we can care less about manually closing clients
      #       otherwise we get a CLOSE_WAIT process hanging around that blocks our port
      server.stop
      expect(client.closed?).to be_true
    end
  end
end<commit_msg>Add failing spec for put/delete<commit_after>require 'spec_helper'
require 'net/ftp'

describe FakeFtp::Server, 'with ftp client' do
  let(:server) { FakeFtp::Server.new(21212, 21213) }
  let(:client) { Net::FTP.new }
  let(:text_filename) { File.expand_path("../fixtures/text_file.txt", File.dirname(__FILE__)) }

  before { server.start }

  after :each do
    client.close
    server.stop
  end

  it 'should accept connections' do
    expect { client.connect('127.0.0.1', 21212) }.to_not raise_error
  end

  context "with client" do
    before { client.connect("127.0.0.1", 21212) }

    it "should allow anonymous authentication" do
      expect { client.login }.to_not raise_error
    end

    it "should allow named authentication" do
      expect { client.login('someone', 'password') }.to_not raise_error
    end

    it "should allow client to quit" do
      expect { client.login('someone', 'password') }.to_not raise_error
      expect { client.quit }.to_not raise_error
    end

    it "should allow mtime" do
      filename = 'someone'
      time = Time.now
      server.add_file(filename, "some data", time)

      client.passive = false
      mtime = client.mtime(filename)
      expect(mtime.to_s).to eql(time.to_s)

      client.passive = true
      mtime = client.mtime(filename)
      expect(mtime.to_s).to eql(time.to_s)
    end

    it "should put files using PASV" do
      expect(File.stat(text_filename).size).to eql(20)

      client.passive = true
      expect { client.put(text_filename) }.to_not raise_error

      expect(server.files).to include('text_file.txt')
      expect(server.file('text_file.txt').bytes).to eql(20)
      expect(server.file('text_file.txt')).to be_passive
      expect(server.file('text_file.txt')).to_not be_active
    end

    it "should put files using active" do
      expect(File.stat(text_filename).size).to eql(20)

      client.passive = false
      expect { client.put(text_filename) }.to_not raise_error

      expect(server.files).to include('text_file.txt')
      expect(server.file('text_file.txt').bytes).to eql(20)
      expect(server.file('text_file.txt')).to_not be_passive
      expect(server.file('text_file.txt')).to be_active
    end

    it 'should be able to delete files added using put' do
      expect(File.stat(text_filename).size).to eql(20)

      client.passive = false
      expect { client.put(text_filename) }.to_not raise_error
      expect(server.files).to include('text_file.txt')
      expect { client.delete(text_filename) }.to_not raise_error
      expect(server.files).to_not include('text_file.txt')
    end

    xit "should disconnect clients on close" do
      # TODO: when this succeeds, we can care less about manually closing clients
      #       otherwise we get a CLOSE_WAIT process hanging around that blocks our port
      server.stop
      expect(client.closed?).to be_true
    end
  end
end
{'fraction_non_alphanumeric': 0.1151560178306092, 'fraction_numerical': 0.015230312035661218, 'mean_word_length': 3.113827349121467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '1340923', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1722, 'n_words': 421}