spec/unit/realtime/client_spec.rb in ably-0.6.2 vs spec/unit/realtime/client_spec.rb in ably-0.7.0
- old
+ new
@@ -1,69 +1,29 @@
+# encoding: utf-8
require 'spec_helper'
-require 'support/protocol_msgbus_helper'
+require 'shared/client_initializer_behaviour'
describe Ably::Realtime::Client do
- let(:client_options) { 'appid.keyuid:keysecret' }
subject do
Ably::Realtime::Client.new(client_options)
end
- context 'delegation to the Rest Client' do
- let(:options) { { arbitrary: 'value' } }
+ it_behaves_like 'a client initializer'
+ context 'delegation to the REST Client' do
+ let(:client_options) { { api_key: 'appid.keyuid:keysecret' } }
+
it 'passes on the options to the initializer' do
- rest_client = instance_double('Ably::Rest::Client', auth: instance_double('Ably::Auth'), options: {})
+ rest_client = instance_double('Ably::Rest::Client', auth: instance_double('Ably::Auth'), options: client_options)
expect(Ably::Rest::Client).to receive(:new).with(client_options).and_return(rest_client)
subject
end
context 'for attribute' do
- [:environment, :use_tls?, :log_level].each do |attribute|
+ [:environment, :use_tls?, :log_level, :custom_host].each do |attribute|
specify "##{attribute}" do
expect(subject.rest_client).to receive(attribute)
subject.public_send attribute
- end
- end
- end
-
- context 'logger' do
- context 'defaults' do
- let(:logger) { subject.logger }
-
- subject { Ably::Realtime::Client.new(client_options) }
-
- it 'uses default Ruby Logger by default' do
- expect(subject.logger.logger).to be_a(::Logger)
- end
-
- it 'defaults to Logger::ERROR log level' do
- expect(subject.logger.log_level).to eql(::Logger::ERROR)
- end
-
- it 'returns the connection ID' do
- allow(subject).to receive_message_chain(:connection, :id).and_return('AAA')
- expect(logger.logger.formatter.call(0, Time.now, '', 'unique_message')).to match(/AAA/)
- end
- end
-
- context 'with custom logger and log_level' do
- let(:custom_logger) do
- Class.new do
- extend Forwardable
- def initialize
- @logger = Logger.new(STDOUT)
- end
- def_delegators :@logger, :fatal, :error, :warn, :info, :debug, :level, :level=
- end
- end
- subject { Ably::Realtime::Client.new(api_key: 'appid.keyuid:keysecret', logger: custom_logger.new, log_level: :debug) }
-
- it 'uses the custom logger' do
- expect(subject.logger.logger.class).to eql(custom_logger)
- end
-
- it 'sets the custom log level' do
- expect(subject.logger.log_level).to eql(Logger::DEBUG)
end
end
end
end
end