Sha256: a07f157b6dc04692fa1e435c9271e84b1f2c3b5191b19f1f7aa8731d4063da6e

Contents?: true

Size: 930 Bytes

Versions: 14

Compression:

Stored size: 930 Bytes

Contents

# 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

14 entries across 14 versions & 1 rubygems

Version Path
telegram-bot-0.16.1 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.16.0 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.15.7 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.15.6 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.15.4 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.15.3 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.15.2 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.15.1 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.15.0 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.14.4 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.14.3 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.14.2 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.14.1 lib/telegram/bot/rspec/message_helpers.rb
telegram-bot-0.14.0 lib/telegram/bot/rspec/message_helpers.rb