Sha256: c2c70d1ec628048f2b6268fbd1b89c009049a3d8580833f8fe3981af55ff4251

Contents?: true

Size: 961 Bytes

Versions: 3

Compression:

Stored size: 961 Bytes

Contents

# frozen_string_literal: true

# Shared helpers for testing message updates.
RSpec.shared_context 'telegram/bot/message_helpers' do
  let(:default_message_options) { {from: from, chat: chat} }
  let(:from) { {id: from_id} }
  let(:from_id) { 123 }
  let(:chat) { {id: chat_id} }
  let(:chat_id) { 456 }

  # Shortcut for dispatching messages with default params.
  def dispatch_message(text, options = {})
    dispatch message: default_message_options.merge(options).merge(text: text)
  end

  # Dispatch command message.
  def dispatch_command(cmd, *args)
    options = args.last.is_a?(Hash) ? args.pop : {}
    args.unshift("/#{cmd}")
    dispatch_message(args.join(' '), options)
  end

  # Matcher to check response. Make sure to define `let(:chat_id)`.
  def respond_with_message(expected = Regexp.new(''))
    raise 'Define chat_id to use respond_with_message' unless defined?(chat_id)
    send_telegram_message(bot, expected, chat_id: chat_id)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
telegram-bot-0.16.5 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.16.4 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.16.3 lib/telegram/bot/rspec/message_helpers.rb