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