Skip to content

Commit

Permalink
Ensure unit tests for Realtime client never connect
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheworiordan committed Nov 5, 2015
1 parent a7226f7 commit 021178d
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions spec/shared/client_initializer_behaviour.rb
Expand Up @@ -103,13 +103,15 @@ def rest?

context 'with a string key instead of options hash' do
before do
allow_any_instance_of(Ably::Realtime::Client).to receive(:auto_connect).and_return(false)
allow_any_instance_of(subject.class).to receive(:auto_connect).and_return(false)
end

let(:client_options) { 'app.key:secret' }

it 'sets the key' do
expect(subject.auth.key).to eql(client_options)
EventMachine.run do
expect(subject.auth.key).to eql(client_options)
end
end

it 'sets the key_name' do
Expand All @@ -126,6 +128,10 @@ def rest?
end

context 'with a string token key instead of options hash' do
before do
allow_any_instance_of(subject.class).to receive(:auto_connect).and_return(false)
end

let(:client_options) { 'app.kjhkasjhdsakdh127g7g1271' }

it 'sets the token' do
Expand All @@ -134,7 +140,7 @@ def rest?
end

context 'with token' do
let(:client_options) { { token: 'token' } }
let(:client_options) { { token: 'token', auth_connect: false } }

it 'sets the token' do
expect(subject.auth.current_token_details.token).to eql('token')
Expand All @@ -159,6 +165,10 @@ def rest?
end

context 'endpoint' do
before do
allow_any_instance_of(subject.class).to receive(:auto_connect).and_return(false)
end

it 'defaults to production' do
expect(subject.endpoint.to_s).to eql("#{protocol}s://#{subdomain}.ably.io")
end
Expand Down Expand Up @@ -207,6 +217,10 @@ def rest?
end

context 'tls' do
before do
allow_any_instance_of(subject.class).to receive(:auto_connect).and_return(false)
end

context 'set to false' do
let(:client_options) { default_options.merge(tls: false, auto_connect: false) }

Expand All @@ -225,6 +239,10 @@ def rest?
end

context 'logger' do
before do
allow_any_instance_of(subject.class).to receive(:auto_connect).and_return(false)
end

context 'default' do
it 'uses Ruby Logger' do
expect(subject.logger.logger).to be_a(::Logger)
Expand Down Expand Up @@ -268,6 +286,10 @@ def initialize
end

context 'delegators' do
before do
allow_any_instance_of(subject.class).to receive(:auto_connect).and_return(false)
end

let(:client_options) { 'app.key:secret' }

it 'delegates :client_id to .auth' do
Expand Down

0 comments on commit 021178d

Please sign in to comment.