spec/rest/client_spec.rb in twilio-ruby-5.42.0 vs spec/rest/client_spec.rb in twilio-ruby-5.43.0
- old
+ new
@@ -1,6 +1,7 @@
require 'spec_helper'
+require 'logger'
describe Twilio::REST::ObsoleteClient do
it 'raise an exception' do
expect { Twilio::REST::ObsoleteClient.new }.to raise_error(Twilio::REST::ObsoleteError)
end
@@ -55,30 +56,33 @@
config.account_sid = 'someSid'
config.auth_token = 'someToken'
config.http_client = 'someClient'
config.region = 'someRegion'
config.edge = 'someEdge'
+ config.logger = 'someLogger'
end
end
it 'uses the global configuration by default' do
@client = Twilio::REST::Client.new
expect(@client.account_sid).to eq('someSid')
expect(@client.auth_token).to eq('someToken')
expect(@client.http_client).to eq('someClient')
expect(@client.region).to eq('someRegion')
expect(@client.edge).to eq('someEdge')
+ expect(@client.logger).to eq('someLogger')
end
it 'uses the arguments over global configuration' do
- @client = Twilio::REST::Client.new('myUser', 'myPassword', nil, 'myRegion', 'myClient')
+ @client = Twilio::REST::Client.new('myUser', 'myPassword', nil, 'myRegion', 'myClient', 'myLogger')
@client.edge = 'myEdge'
expect(@client.account_sid).to eq('myUser')
expect(@client.auth_token).to eq('myPassword')
expect(@client.http_client).to eq('myClient')
expect(@client.region).to eq('myRegion')
expect(@client.edge).to eq('myEdge')
+ expect(@client.logger).to eq('myLogger')
end
class MyVersion < Twilio::REST::Version
def initialize(domain)
super
@@ -95,17 +99,18 @@
end
end
end
context 'validation' do
- before do
+ before :all do
Twilio.configure do |config|
config.account_sid = 'someSid'
config.auth_token = 'someToken'
config.http_client = 'someClient'
config.region = nil
config.edge = nil
+ config.logger = nil
end
end
it 'successfully validates the working SSL certificate' do
@holodeck.mock Twilio::Response.new(200, '')
@@ -137,9 +142,26 @@
expect(error.code).to eq(20_001)
expect(error.details).to eq({ 'foo' => 'bar' })
expect(error.error_message).to eq('Bad request')
expect(error.more_info).to eq('https://www.twilio.com/docs/errors/20001')
}
+ end
+ end
+
+ context 'logging' do
+ it 'logs the call details' do
+ @client.logger = Logger.new(STDOUT)
+ @holodeck.mock Twilio::Response.new(200, {})
+ expect {
+ @client.request('host', 'port', 'GET', 'http://foobar.com')
+ }.to output(/Host:foobar.com/).to_stdout_from_any_process
+ end
+
+ it 'does not log when the logger instance is not passed' do
+ @holodeck.mock Twilio::Response.new(200, {})
+ expect {
+ @client.request('host', 'port', 'GET', 'http://foobar.com')
+ }.to_not output(/Host:foobar.com/).to_stdout_from_any_process
end
end
describe '#build_uri' do
before(:all) do