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