spec/lib/events/subscribe_spec.rb in pubnub-4.0.27 vs spec/lib/events/subscribe_spec.rb in pubnub-4.0.28

- old
+ new

@@ -1,36 +1,35 @@ -require 'spec_helper' +require "spec_helper" describe Pubnub::Subscribe do # it_behaves_like 'an event' around :each do |example| - Celluloid.boot - example.run - Celluloid.shutdown + example.run_with_retry retry: 10 end - context 'given basic parameters' do + + context "given basic parameters" do before :each do @messages = [] @statuses = [] @callbacks = Pubnub::SubscribeCallback.new( - message: ->(envelope) { @messages << envelope }, - presence: ->(_envelope) {}, - status: ->(envelope) { @statuses << envelope } + message: -> (envelope) { @messages << envelope }, + presence: -> (_envelope) { }, + status: -> (envelope) { @statuses << envelope }, ) end - context 'async' do - it 'works' do - VCR.use_cassette('lib/events/subscribe-async', record: :once) do + context "async" do + it "works" do + VCR.use_cassette("lib/events/subscribe-async", record: :once) do @pubnub = Pubnub::Client.new( - subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f', - publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4', - auth_key: 'ruby-test-auth', - uuid: 'ruby-test-uuid' + subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f", + publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4", + auth_key: "ruby-test-auth", + uuid: "ruby-test-uuid", ) @pubnub.add_listener(callback: @callbacks) @pubnub.subscribe(channel: :demo) @@ -38,57 +37,55 @@ eventually do envelope = @messages.first expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema end - end end - it 'works with cipher key' do + it "works with cipher key" do @pubnub = Pubnub::Client.new( - subscribe_key: 'demo', - publish_key: 'demo', - uuid: 'ruby-test-uuid', - cipher_key: 'demo' + subscribe_key: "demo", + publish_key: "demo", + uuid: "ruby-test-uuid", + cipher_key: "demo", ) @pubnub.add_listener(callback: @callbacks) - VCR.use_cassette('lib/events/subscribe-cipher-async', record: :once) do + VCR.use_cassette("lib/events/subscribe-cipher-async", record: :once) do @pubnub.subscribe(channel: :whatever) eventually do - expect(@messages.first.result[:data][:message]).to eq('text' => 'hey') + expect(@messages.first.result[:data][:message]).to eq("text" => "hey") end end end - it 'allows subscribing additional channels' do + it "allows subscribing additional channels" do @pubnub = Pubnub::Client.new( - subscribe_key: 'demo', - publish_key: 'demo', - uuid: 'ruby-test-uuid' + subscribe_key: "demo", + publish_key: "demo", + uuid: "ruby-test-uuid", ) - VCR.use_cassette('lib/events/subscribe-playing-async', record: :once) do + VCR.use_cassette("lib/events/subscribe-playing-async", record: :once) do @pubnub.subscribe(channel: :demo) #sleep(0.1) @pubnub.subscribe(channel: :whatever) #sleep(0.1) @pubnub.leave(channel: [:whatever, :demo]) end - end - it 'fires status callback on error' do - VCR.use_cassette('lib/events/subscribe-async-error', record: :once) do + it "fires status callback on error" do + VCR.use_cassette("lib/events/subscribe-async-error", record: :once) do @pubnub = Pubnub::Client.new( - subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f', - publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4', - auth_key: 'ruby-test-auth', - uuid: 'ruby-test-uuid' + subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f", + publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4", + auth_key: "ruby-test-auth", + uuid: "ruby-test-uuid", ) @pubnub.add_listener(callback: @callbacks) @pubnub.subscribe(channel: :demo) @@ -97,102 +94,95 @@ eventually do envelope = @statuses.first expect(envelope).to be_a_kind_of Pubnub::ErrorEnvelope expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema end - end end end - context 'sync' do - it 'works with cipher key' do + context "sync" do + it "works with cipher key" do @pubnub = Pubnub::Client.new( - subscribe_key: 'demo', - publish_key: 'demo', - uuid: 'ruby-test-uuid', - cipher_key: 'demo' + subscribe_key: "demo", + publish_key: "demo", + uuid: "ruby-test-uuid", + cipher_key: "demo", ) - VCR.use_cassette('lib/events/subscribe-cipher-async', record: :once) do + VCR.use_cassette("lib/events/subscribe-cipher-async", record: :once) do @pubnub.subscribe(channel: :whatever, http_sync: true) @messages = @pubnub.subscribe(channel: :whatever, http_sync: true) eventually do - expect(@messages.first.result[:data][:message]).to eq('text' => 'hey') + expect(@messages.first.result[:data][:message]).to eq("text" => "hey") end end end - it 'works' do - VCR.use_cassette('lib/events/subscribe-sync', record: :once) do + it "works" do + VCR.use_cassette("lib/events/subscribe-sync", record: :once) do @pubnub = Pubnub::Client.new( - subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f', - publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4', - auth_key: 'ruby-test-auth', - uuid: 'ruby-test-uuid' + subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f", + publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4", + auth_key: "ruby-test-auth", + uuid: "ruby-test-uuid", ) @pubnub.subscribe(channel: :demo, http_sync: true) envelopes = @pubnub.subscribe(channel: :demo, http_sync: true) - envelope = envelopes.first expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema - end end - it 'fires status callback on error' do - VCR.use_cassette('lib/events/subscribe-sync-error', record: :once) do + it "fires status callback on error" do + VCR.use_cassette("lib/events/subscribe-sync-error", record: :once) do @pubnub = Pubnub::Client.new( - subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f', - publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4', - auth_key: 'ruby-test-auth', - uuid: 'ruby-test-uuid' + subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f", + publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4", + auth_key: "ruby-test-auth", + uuid: "ruby-test-uuid", ) @pubnub.subscribe(channel: :demo, http_sync: true) envelopes = @pubnub.subscribe(channel: :demo, http_sync: true) envelope = envelopes.first expect(envelope).to be_a_kind_of Pubnub::ErrorEnvelope expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema - end end end - context 'aliases' do - it 'pass channels to channel' do - VCR.use_cassette('lib/events/subscribe-sync', record: :once) do + context "aliases" do + it "pass channels to channel" do + VCR.use_cassette("lib/events/subscribe-sync", record: :once) do @pubnub = Pubnub::Client.new( - subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f', - publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4', - auth_key: 'ruby-test-auth', - uuid: 'ruby-test-uuid' + subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f", + publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4", + auth_key: "ruby-test-auth", + uuid: "ruby-test-uuid", ) @pubnub.subscribe(channels: :demo, http_sync: true) envelopes = @pubnub.subscribe(channels: :demo, http_sync: true) - envelope = envelopes.first expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema - end end - it 'pass channel_groups to channel_group' do - VCR.use_cassette('lib/events/subscribe-channel-groups', record: :once) do - + it "pass channel_groups to channel_group" do + VCR.use_cassette("lib/events/subscribe-channel-groups", record: :once) do @pubnub = Pubnub::Client.new( - subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f', - publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4', - auth_key: 'ruby-test-auth', - uuid: 'ruby-test-uuid' + subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f", + publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4", + auth_key: "ruby-test-auth", + uuid: "ruby-test-uuid", ) @pubnub.subscribe(channel_groups: :demo, http_sync: true) envelopes = @pubnub.subscribe(channel_groups: :demo, http_sync: true) @@ -201,26 +191,26 @@ expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema end end end - context 'flags' do - it 'with with_presence' do - VCR.use_cassette('lib/events/subscribe-with-presence', record: :once) do + context "flags" do + it "with with_presence" do + VCR.use_cassette("lib/events/subscribe-with-presence", record: :once) do @pubnub = Pubnub::Client.new( - subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f', - publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4', - auth_key: 'ruby-test-auth', - uuid: 'ruby-test-uuid' + subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f", + publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4", + auth_key: "ruby-test-auth", + uuid: "ruby-test-uuid", ) - @pubnub.subscribe(channels: [:demo, :demo1, 'demo.*'], with_presence: true, http_sync: true) - envelopes = @pubnub.subscribe(channels: [:demo, :demo1, 'demo.*'], with_presence: true, http_sync: true) + @pubnub.subscribe(channels: [:demo, :demo1, "demo.*"], with_presence: true, http_sync: true) + envelopes = @pubnub.subscribe(channels: [:demo, :demo1, "demo.*"], with_presence: true, http_sync: true) envelope = envelopes.first expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema end end end end -end \ No newline at end of file +end