зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-03 17:55:52 +03:00
Make integration & controller specs consistent
Этот коммит содержится в:
@@ -1,37 +1,30 @@
|
||||
require 'telegram/bot/updates_controller/testing'
|
||||
require 'telegram/bot/rspec/message_helpers'
|
||||
|
||||
RSpec.shared_context 'telegram/bot/updates_controller' do
|
||||
include Telegram::Bot::RSpec::ClientMatchers
|
||||
include_context 'telegram/bot/message_helpers'
|
||||
|
||||
let(:controller_class) { described_class }
|
||||
let(:controller) do
|
||||
controller_class.new(bot, update).tap do |x|
|
||||
controller_class.new(*controller_args).tap do |x|
|
||||
x.extend Telegram::Bot::UpdatesController::Testing
|
||||
end
|
||||
end
|
||||
let(:update) { build_update(payload_type, payload) }
|
||||
let(:controller_args) { [bot, deep_stringify(update)] }
|
||||
let(:update) { {payload_type => payload} }
|
||||
let(:payload_type) { :some_type }
|
||||
let(:payload) { double(:payload) }
|
||||
let(:bot) { Telegram::Bot::ClientStub.new(bot_name) }
|
||||
let(:bot_name) { 'bot' }
|
||||
let(:session) { controller.send(:session) }
|
||||
let(:from_id) { 123 }
|
||||
let(:chat_id) { 456 }
|
||||
let(:default_message_options) { {from: {id: from_id}, chat: {id: chat_id}} }
|
||||
|
||||
include Telegram::Bot::RSpec::ClientMatchers
|
||||
|
||||
def dispatch(bot = self.bot, update = self.update)
|
||||
controller.dispatch_again(bot, update)
|
||||
end
|
||||
|
||||
def dispatch_message(text, options = {})
|
||||
update = build_update :message, default_message_options.merge(options).merge(text: text)
|
||||
dispatch bot, update
|
||||
end
|
||||
|
||||
def build_update(type, content)
|
||||
deep_stringify type => content
|
||||
# Process update.
|
||||
def dispatch(update = self.update, bot = self.bot)
|
||||
controller.dispatch_again(bot, deep_stringify(update))
|
||||
end
|
||||
|
||||
# Same as `.as_json` but mocks-friendly.
|
||||
def deep_stringify(input)
|
||||
case input
|
||||
when Array then input.map(&method(__callee__))
|
||||
@@ -39,11 +32,6 @@ RSpec.shared_context 'telegram/bot/updates_controller' do
|
||||
else input
|
||||
end
|
||||
end
|
||||
|
||||
# Matcher to check response. Make sure to define `let(:chat_id)`.
|
||||
def respond_with_message(expected)
|
||||
send_telegram_message(bot, expected, chat_id: chat_id)
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
||||
Ссылка в новой задаче
Block a user