spec/lib/events/grant_spec.rb in pubnub-4.0.23 vs spec/lib/events/grant_spec.rb in pubnub-4.0.25

- old
+ new

@@ -9,55 +9,54 @@ Celluloid.shutdown end context 'given basic parameters' do before :each do - Pubnub::Grant.any_instance.stub(:current_time).and_return 1463146850 - Pubnub::Grant.any_instance.stub(:signature).and_return 'udCXAk-z4VaU2JA2LgjVzED2LBZAKsjj86twYJoGPnY=' - - @pubnub = Pubnub::Client.new( - subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f', - publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4', - secret_key: 'sec-c-OWIyYmVlYWYtYWMxMS00OTcxLTlhZDAtZDBlYTM4ODE1MWUy', - auth_key: 'ruby-test-auth', - uuid: 'ruby-test-uuid' + allow_any_instance_of(Pubnub::Grant).to receive(:current_time).and_return 1463146850 + allow_any_instance_of(Pubnub::Grant).to receive(:signature).and_return 'udCXAk-z4VaU2JA2LgjVzED2LBZAKsjj86twYJoGPnY=' + end + let(:pubnub) do + Pubnub::Client.new( + subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f', + publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4', + secret_key: 'sec-c-OWIyYmVlYWYtYWMxMS00OTcxLTlhZDAtZDBlYTM4ODE1MWUy', + auth_key: 'ruby-test-auth', + uuid: 'ruby-test-uuid' ) end + let(:envelope) do + pubnub.grant( + channel: :demo + ).value + end it 'works' do VCR.use_cassette('lib/events/grant', record: :once) do - envelope = @pubnub.grant( - channel: :demo - ).value - expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema end end it 'forms valid ErrorEnvelope on error' do VCR.use_cassette('lib/events/grant-error', record: :once) do - envelope = @pubnub.grant( - channel: :demo - ).value - expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema end end - it 'forms valid ErrorEnvelope on timeout error' do - HTTPClient.any_instance.stub(get: HTTPClient::ReceiveTimeoutError.new) + [ + HTTPClient::ConnectTimeoutError, + HTTPClient::ReceiveTimeoutError, + HTTPClient::SendTimeoutError + ].each do |error_class| + it "forms valid ErrorEnvelope on #{error_class}" do + allow_any_instance_of(HTTPClient).to receive(:get).and_return error_class.new - envelope = @pubnub.grant( - channel: :demo - ).value - - expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true - expect(envelope.status[:code]).to eq 408 - expect(envelope.status[:category]).to eq Pubnub::Constants::STATUS_TIMEOUT - expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema + expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true + expect(envelope.status[:code]).to eq 408 + expect(envelope.status[:category]).to eq Pubnub::Constants::STATUS_TIMEOUT + expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema + end end end - end