lib/telegram/bot/updates_controller/rspec_helpers.rb in telegram-bot-0.9.0 vs lib/telegram/bot/updates_controller/rspec_helpers.rb in telegram-bot-0.10.0

- old
+ new

@@ -11,20 +11,22 @@ let(:payload_type) { :some_type } let(:payload) { double(:payload) } let(:bot) { Telegram::Bot::ClientStub.new(bot_name) } let(:bot_name) { 'bot' } let(:session) { controller.send(:session) } + let(:from_id) { 123 } + let(:chat_id) { 456 } + let(:default_message_options) { {from: {id: from_id}, chat: {id: chat_id}} } include Telegram::Bot::RSpec::ClientMatchers def dispatch(bot = self.bot, update = self.update) controller.dispatch_again(bot, update) end - def dispatch_message(text, options = nil) - options ||= respond_to?(:default_message_options) ? default_message_options : {} - update = build_update :message, options.merge(text: text) + def dispatch_message(text, options = {}) + update = build_update :message, default_message_options.merge(options).merge(text: text) dispatch bot, update end def build_update(type, content) deep_stringify type => content @@ -39,7 +41,13 @@ end # Matcher to check response. Make sure to define `let(:chat_id)`. def respond_with_message(expected) send_telegram_message(bot, expected, chat_id: chat_id) + end +end + +RSpec.configure do |config| + if config.respond_to?(:include_context) + config.include_context 'telegram/bot/updates_controller', type: :telegram_bot_controller end end