From 0320507abe26d722627eef5dd12e1a367a5983f0 Mon Sep 17 00:00:00 2001 From: Max Melentiev Date: Thu, 11 May 2017 13:57:29 +0600 Subject: [PATCH] Telegram.bot raises error when there is no default config --- lib/telegram/bot/config_methods.rb | 6 +++++- spec/telegram/bot/config_methods_spec.rb | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/telegram/bot/config_methods.rb b/lib/telegram/bot/config_methods.rb index d2f1f73..be4ef2e 100644 --- a/lib/telegram/bot/config_methods.rb +++ b/lib/telegram/bot/config_methods.rb @@ -34,7 +34,11 @@ module Telegram # Default bot. def bot - @bot ||= bots[:default] + @bot ||= bots.fetch(:default) do + raise 'Default bot is not configured.' \ + ' Add :default to bots_config' \ + ' or use telegram.bot/telegram.bots.default section in secrets.yml.' + end end # Hash of botan clients made from #bots. diff --git a/spec/telegram/bot/config_methods_spec.rb b/spec/telegram/bot/config_methods_spec.rb index 2657750..b1c6a37 100644 --- a/spec/telegram/bot/config_methods_spec.rb +++ b/spec/telegram/bot/config_methods_spec.rb @@ -22,8 +22,13 @@ RSpec.describe Telegram::Bot::ConfigMethods do end describe '#bot' do - subject { registry.bot } - it { should eq registry.bots[:default] } + subject { -> { registry.bot } } + its(:call) { should eq registry.bots[:default] } + + context 'when bot is not configured' do + let(:config) { super().except(:default) } + it { should raise_error(/bot is not configured/) } + end end describe '#bots' do