class Object

Public Instance Methods

answer_callback_query(text = Regexp.new(''), options = {}) click to toggle source

Matcher to check that callback query is answered.

# File lib/telegram/bot/rspec/callback_query_helpers.rb, line 28
def answer_callback_query(text = Regexp.new(''), options = {})
  description = "answer callback query with #{text.inspect}"
  text = a_string_matching(text) if text.is_a?(Regexp)
  options = options.merge(
    callback_query_id: payload[:id],
    text: text,
  )
  Telegram::Bot::RSpec::ClientMatchers::MakeTelegramRequest.new(
    bot, :answerCallbackQuery, description: description
  ).with(hash_including(options))
end
deep_stringify(input) click to toggle source

Same as `.as_json` but mocks-friendly.

# File lib/telegram/bot/updates_controller/rspec_helpers.rb, line 30
def deep_stringify(input)
  case input
  when Array then input.map(&method(__callee__))
  when Hash then input.map { |k, v| [k.to_s, deep_stringify(v)] }.to_h
  else input
  end
end
dispatch(update) click to toggle source
# File lib/telegram/bot/rspec/integration/poller.rb, line 7
def dispatch(update)
  controller_class.dispatch(bot, update.as_json)
end
dispatch_command(cmd, *args) click to toggle source

Dispatch command message.

# File lib/telegram/bot/rspec/message_helpers.rb, line 15
def dispatch_command(cmd, *args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  args.unshift("/#{cmd}")
  dispatch_message(args.join(' '), options)
end
dispatch_message(text, options = {}) click to toggle source

Shortcut for dispatching messages with default params.

# File lib/telegram/bot/rspec/message_helpers.rb, line 10
def dispatch_message(text, options = {})
  dispatch message: default_message_options.merge(options).merge(text: text)
end
edit_current_message(type, options = {}) click to toggle source

Matcher to check that origin message got edited.

# File lib/telegram/bot/rspec/callback_query_helpers.rb, line 16
def edit_current_message(type, options = {})
  description = 'edit current message'
  options = options.merge(
    message_id: message[:message_id],
    chat_id: chat_id,
  )
  Telegram::Bot::RSpec::ClientMatchers::MakeTelegramRequest.new(
    bot, :"editMessage#{type.to_s.camelize}", description: description
  ).with(hash_including(options))
end
respond_with_message(expected = Regexp.new('')) click to toggle source

Matcher to check response. Make sure to define `let(:chat_id)`.

# File lib/telegram/bot/rspec/message_helpers.rb, line 22
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