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)


135
136
137
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 135

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.



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

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