Sha256: 17bdfbfa09d3d1ff6e34790b9c2616180098a5feb791a31e95d08491ca73ef38

Contents?: true

Size: 1.81 KB

Versions: 8

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe Pubnub::Client do
  it 'has valid version constant' do
    expect(Pubnub::Client::VERSION).to match(/\d+\.\d+\..+/)
  end

  context '#inititalize' do
    it 'requires arguments' do
      expect{ Pubnub.new() }.to raise_error
    end

    context 'parameter :subscribe_key' do
      it 'is required' do
        expect{ Pubnub.new(:http_sync => true) }.to raise_error(Pubnub::InitializationError)
      end

      it 'must be valid' do
        expect{ Pubnub.new(:subscribe_key => 123) }.to raise_error(Pubnub::InitializationError)
        expect{ Pubnub.new(:subscribe_key => [] ) }.to raise_error(Pubnub::InitializationError)
        expect{ Pubnub.new(:subscribe_key => {} ) }.to raise_error(Pubnub::InitializationError)

        expect{ Pubnub.new(:subscribe_key => 'key') }.not_to raise_error
        expect{ Pubnub.new(:subscribe_key => :key ) }.not_to raise_error
      end
    end

    context 'parameter :publish_key' do
      it 'must be valid' do
        expect{ Pubnub.new(:subscribe_key => 'valid', :publish_key => ['invalid']) }.to raise_error(Pubnub::InitializationError)
        expect{ Pubnub.new(:subscribe_key => 'valid', :publish_key => {'invalid' => 'yeah'}) }.to raise_error(Pubnub::InitializationError)
        expect{ Pubnub.new(:subscribe_key => 'valid', :publish_key => ['invalid']) }.to raise_error(Pubnub::InitializationError)

        expect{ Pubnub.new(:subscribe_key => 'valid', :publish_key => 'key') }.not_to raise_error
        expect{ Pubnub.new(:subscribe_key => 'valid', :publish_key => :key ) }.not_to raise_error
      end
    end

    it 'starts EventMachine reactor in a separate thread' do
      pubnub = Pubnub.new(:subscribe_key => 'key')
      sleep(0.1)
      expect(EM.reactor_running?).to be true
      expect(EM.reactor_thread).not_to be eq Thread.current
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pubnub-3.5.14 spec/lib/client_spec.rb
pubnub-3.5.12 spec/lib/client_spec.rb
pubnub-3.5.8 spec/lib/client_spec.rb
pubnub-3.5.7 spec/lib/client_spec.rb
pubnub-3.5.6 spec/lib/client_spec.rb
pubnub-3.5.5 spec/lib/client_spec.rb
pubnub-3.5.3 spec/lib/client_spec.rb
pubnub-3.5.1 spec/lib/client_spec.rb