spec/slack/real_time/client_spec.rb in slack-ruby-client-0.6.0 vs spec/slack/real_time/client_spec.rb in slack-ruby-client-0.7.0
- old
+ new
@@ -42,16 +42,16 @@
expect(client.web_client.token).to eq 'local token'
end
end
end
context 'client' do
- let(:client) { Slack::RealTime::Client.new }
context 'started' do
+ let(:client) { Slack::RealTime::Client.new(store_class: Slack::RealTime::Stores::Store) }
describe '#start!' do
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
before do
- allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30).and_return(socket)
+ allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
allow(socket).to receive(:connect!)
allow(socket).to receive(:start_sync).and_yield
client.start!
end
context 'properties provided upon connection' do
@@ -68,11 +68,11 @@
it 'sets self' do
expect(client.self.id).to eq 'U07518DTL'
end
it 'sets users' do
expect(client.users.count).to eq 18
- expect(client.users.values.first['id']).to eq 'U092BDCLV'
+ expect(client.users.values.first['id']).to eq 'U07518DTL'
end
it 'sets channels' do
expect(client.channels.count).to eq 37
expect(client.channels.values.first['name']).to eq 'a1'
end
@@ -136,11 +136,11 @@
it 'team' do
expect(client.team).to be nil
end
end
context 'subclassed' do
- let(:client) { Class.new(Slack::RealTime::Client).new }
+ let(:client) { Class.new(Slack::RealTime::Client).new(store_class: Slack::RealTime::Stores::Store) }
it 'runs event handlers' do
event = Slack::RealTime::Event.new(
'type' => 'team_rename',
'name' => 'New Team Name Inc.'
)
@@ -149,18 +149,25 @@
end
end
end
end
context 'with defaults' do
+ let(:client) { Slack::RealTime::Client.new }
describe '#initialize' do
it 'sets ping' do
expect(client.websocket_ping).to eq 30
end
it "doesn't set proxy" do
expect(client.websocket_proxy).to be nil
end
- Slack::RealTime::Config::ATTRIBUTES.each do |key|
+ it 'defaults logger' do
+ expect(client.send(:logger)).to be_a ::Logger
+ end
+ it 'sets default store_class' do
+ expect(client.send(:store_class)).to eq Slack::RealTime::Store
+ end
+ (Slack::RealTime::Config::ATTRIBUTES - [:logger, :store_class]).each do |key|
it "sets #{key}" do
expect(client.send(key)).to eq Slack::RealTime::Config.send(key)
end
end
end
@@ -250,9 +257,37 @@
allow(socket).to receive(:start_sync).and_yield
end
it 'calls rtm_start with start options' do
expect(client.web_client).to receive(:rtm_start).with(simple_latest: true).and_call_original
client.start!
+ end
+ end
+ end
+ end
+ context 'store_class' do
+ before do
+ Slack::RealTime::Client.configure do |config|
+ config.store_class = Slack::RealTime::Stores::Starter
+ end
+ end
+ describe '#initialize' do
+ it 'can be overriden explicitly' do
+ client = Slack::RealTime::Client.new(store_class: Slack::RealTime::Store)
+ expect(client.send(:store_class)).to eq Slack::RealTime::Store
+ end
+ it 'sets store_class' do
+ expect(client.send(:store_class)).to eq(Slack::RealTime::Stores::Starter)
+ end
+ context 'start!' do
+ let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
+ before do
+ allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
+ allow(socket).to receive(:connect!)
+ allow(socket).to receive(:start_sync).and_yield
+ end
+ it 'instantiates the correct store class' do
+ client.start!
+ expect(client.store).to be_a Slack::RealTime::Stores::Starter
end
end
end
end
end