spec/unit/realtime/client_spec.rb in ably-0.1.6 vs spec/unit/realtime/client_spec.rb in ably-0.2.0
- old
+ new
@@ -1,7 +1,7 @@
require 'spec_helper'
-require "support/protocol_msgbus_helper"
+require 'support/protocol_msgbus_helper'
describe Ably::Realtime::Client do
let(:client_options) { 'appid.keyuid:keysecret' }
subject do
Ably::Realtime::Client.new(client_options)
@@ -25,13 +25,55 @@
expect(subject.rest_client).to receive(:stats).with(options)
subject.stats options
end
context 'for attribute' do
- [:environment, :use_tls?, :logger, :log_level].each do |attribute|
+ [:environment, :use_tls?, :log_level].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