<commit_before>require 'spec_helper'

describe Damage::Client::Base do
  let(:mixin) { self.described_class }
  let(:klass) { Class.new(Object) do; end }
  let(:instance) { klass.new([], options) }

  before { klass.send(:include, mixin) }
  
  let(:host) { '127.0.0.1' }
  let(:port) { 16990 }
  let(:schema_name) { "TTFIX42" }
  let(:schema) { Damage::Schema.new("schemas/#{schema_name}.xml") }
  let(:base_options) { {server_ip: host, port: port, schema_name: schema_name} }
  let(:options) { base_options }
  let(:server) { Damage::FakeFixServer.new(host, port, schema) }

  subject { instance }

  around do |ex|
    Celluloid.boot
    ex.run
    Celluloid.shutdown
  end

  before do
    #Celluloid.logger = nil
    server

    instance
  end

  after do
    server.terminate
  end

  describe "#can_login_again?" do
    let(:current_time) { Time.new(2015, 8, 6, 11, 40, 0) }
    subject { instance.can_login_again?(current_time) }
    it "should be true if logout time isn't set" do
      instance.logout_time.should be_nil
      subject.should eq true
    end

    it "should be true if logout time is over 15 seconds before current" do
      instance.logout_time = Time.new(2015, 8, 6, 11, 40, 16)
      subject.should eq true
    end

    it "should be false if logout time is less than 15 seconds before current" do
      instance.logout_time = Time.new(2015, 8, 6, 11, 40, 10)
      subject.should eq true
    end

    it "should be false if logout time is equal to 15 seconds before current" do
      instance.logout_time = Time.new(2015, 8, 6, 11, 40, 15)
      subject.should eq true
    end
 end

  describe '#default_headers' do
    subject { instance.default_headers }
    let(:id_options) { { sender_id: sender_id, target_id: target_id } }
    let(:sender_id) { 1234 }
    let(:target_id) { 4567 }
    
    it { should be_a Hash }
    it { should include 'SenderCompID' }
    it { should include 'TargetCompID' }
    it { should include 'MsgSeqNum' => 2 }

    context 'include the sender and target ids' do
      let(:options) { id_options.merge(base_options) }
      it { should include 'SenderCompID' => sender_id }
      it { should include 'TargetCompID' => target_id }
    end<commit_msg>stub logout time<commit_after>require 'spec_helper'

describe Damage::Client::Base do
  let(:mixin) { self.described_class }
  let(:klass) { Class.new(Object) do; end }
  let(:instance) { klass.new([], options) }

  before { klass.send(:include, mixin) }
  
  let(:host) { '127.0.0.1' }
  let(:port) { 16990 }
  let(:schema_name) { "TTFIX42" }
  let(:schema) { Damage::Schema.new("schemas/#{schema_name}.xml") }
  let(:base_options) { {server_ip: host, port: port, schema_name: schema_name} }
  let(:options) { base_options }
  let(:server) { Damage::FakeFixServer.new(host, port, schema) }

  subject { instance }

  around do |ex|
    Celluloid.boot
    ex.run
    Celluloid.shutdown
  end

  before do
    #Celluloid.logger = nil
    server

    instance
  end

  after do
    server.terminate
  end

  describe "#can_login_again?" do
    let(:current_time) { Time.new(2015, 8, 6, 11, 40, 0) }
    subject { instance.can_login_again?(current_time) }
    it "should be true if logout time isn't set" do
      subject.should eq true
    end

    it "should be true if logout time is over 15 seconds before current" do
      instance.stub(:logout_time).and_return(Time.new(2015, 8, 6, 11, 40, 16))
      subject.should eq true
    end

    it "should be false if logout time is less than 15 seconds before current" do
      instance.stub(:logout_time).and_return(Time.new(2015, 8, 6, 11, 40, 10))
      subject.should eq true
    end

    it "should be false if logout time is equal to 15 seconds before current" do
      instance.stub(:logout_time).and_return(Time.new(2015, 8, 6, 11, 40, 15))
      subject.should eq true
    end
 end

  describe '#default_headers' do
    subject { instance.default_headers }
    let(:id_options) { { sender_id: sender_id, target_id: target_id } }
    let(:sender_id) { 1234 }
    let(:target_id) { 4567 }
    
    it { should be_a Hash }
    it { should include 'SenderCompID' }
    it { should include 'TargetCompID' }
    it { should include 'MsgSeqNum' => 2 }

    context 'include the sender and target ids' do
      let(:options) { id_options.merge(base_options) }
      it { should include 'SenderCompID' => sender_id }
      it { should include 'TargetCompID' => target_id }
    end
{'fraction_non_alphanumeric': 0.11691822482541113, 'fraction_numerical': 0.03379139445821131, 'mean_word_length': 3.1340782122905027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 2, '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': '6183501', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1476, 'n_words': 428}