class Telegram::Bot::ClientStub
Stubbed client for tests. Saves all requests into requests
hash.
Attributes
requests[R]
Public Class Methods
new(token = nil, username = nil, **options)
click to toggle source
# File lib/telegram/bot/client_stub.rb, line 37 def initialize(token = nil, username = nil, **options) @token = token || options[:token] @username = username || options[:username] || token reset end
stub_all!(enabled = true) { || ... }
click to toggle source
Any call to Client.new
will return ClientStub
instance when `enabled` is true. Can be used with a block.
# File lib/telegram/bot/client_stub.rb, line 20 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
stub_all?()
click to toggle source
# File lib/telegram/bot/client_stub.rb, line 32 def stub_all? @_stub_all end
Public Instance Methods
request(action, body = {})
click to toggle source
# File lib/telegram/bot/client_stub.rb, line 47 def request(action, body = {}) requests[action.to_sym] << body end
reset()
click to toggle source
# File lib/telegram/bot/client_stub.rb, line 43 def reset @requests = Hash.new { |h, k| h[k] = [] } end