зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-03 09:46:17 +03:00
Ability to stub all clients.
Этот коммит содержится в:
@@ -4,6 +4,35 @@ module Telegram
|
||||
class ClientStub < Client
|
||||
attr_reader :requests
|
||||
|
||||
module StubbedConstructor
|
||||
def new(*args)
|
||||
if self == ClientStub || !ClientStub.stub_all?
|
||||
super
|
||||
else
|
||||
ClientStub.new(args[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
# Makes all
|
||||
def stub_all!(enabled = true)
|
||||
Client.extend(StubbedConstructor) unless Client < StubbedConstructor
|
||||
return @_stub_all = enabled unless block_given?
|
||||
begin
|
||||
old = @_stub_all
|
||||
stub_all!(enabled)
|
||||
yield
|
||||
ensure
|
||||
stub_all!(old)
|
||||
end
|
||||
end
|
||||
|
||||
def stub_all?
|
||||
@_stub_all
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(username = nil)
|
||||
@username = username
|
||||
reset
|
||||
|
||||
@@ -41,6 +41,13 @@ module Telegram
|
||||
config[:default] = default if default
|
||||
end
|
||||
end
|
||||
|
||||
# Resets all cached bots and their configs.
|
||||
def reset_bots
|
||||
@bots = nil
|
||||
@bot = nil
|
||||
@bots_config = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Ссылка в новой задаче
Block a user