Sha256: 9796ea47fc0e7ef528de3753e3fc1948888177d589eee431e387f5ca582f341f

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 = FayeHandshake.new
      @socket = FayeSocket.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.3.0 spec/filter_spec.rb