Module: Telegram::Bot::RSpec::ClientMatchers

Defined in:
lib/telegram/bot/rspec/client_matchers.rb

Overview

Matchers to test requests to Telegram API.

Complex matchers requires ‘rspec-mocks` to be installed.

Defined Under Namespace

Classes: MakeTelegramRequest

Instance Method Summary collapse

Instance Method Details

#make_telegram_request(bot, action) ⇒ Object

Check that bot performed request to telegram API:

expect { dispatch_message('Hi!') }.
  to make_telegram_request(bot, :sendMessage).
  with(text: 'Hello!', chat_id: chat_id)


137
138
139
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 137

def make_telegram_request(bot, action)
  MakeTelegramRequest.new(bot, action)
end

#send_telegram_message(bot, text = nil, options = {}) ⇒ Object

Helper for asserting message is sent. Note that options are checked with ‘hash_including`. For strict checks use #make_telegram_request.



143
144
145
146
147
148
149
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 143

def send_telegram_message(bot, text = nil, options = {})
  description = "send telegram message #{text.inspect}"
  text = a_string_matching(text) if text.is_a?(Regexp)
  options = options.merge(text: text) if text
  MakeTelegramRequest.new(bot, :sendMessage, description: description).
    with(hash_including(options))
end