Sha256: 69a07e1e75d0a016c619fc494b8af290b162a4fc68b31fc5f70e96ecdf69b5b3

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe Hara::Filter do
  before :all do
    @filter = Class.new do
      include Hara::Filter
      self.pool_size = 3

      def filter
        socket.remote_ip == 'localhost'
      end
    end
  end

  it 'Hara.filter_class should be set' do
    Hara.filter_class.should == @filter
  end

  it 'Hara.filter_pool_size should be set' do
    Hara.filter_pool_size.should == 3
  end

  it 'Hara.filter_pool should work' do
    wait_until{Hara.filter_pool}
    Hara.filter_pool.nil?.should == false
  end

  describe 'filter' do
    before :each do
      @handshake = FakeHandshake.new
      @socket = FakeSocket.new
      @socket.alive = true
      wait_until{Hara.filter_pool}
    end

    it 'filter should close socket if not pass' do
      @socket.remote_ip = '127.0.0.1'
      Hara.filter_pool.run_filter @handshake, @socket
      wait_until{!@socket.alive?}
      @socket.alive?.should == false
    end

    it 'filter should set callbacks on socket if pass' do
      @socket.remote_ip = 'localhost'
      Hara.filter_pool.run_filter @handshake, @socket
      wait_until{@socket.onclose_block}
      @socket.onmessage_block.should.is_a? Proc
      @socket.onclose_block.should.is_a? Proc
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hara-0.4.0 spec/filter_spec.rb