Class: Telegram::Bot::ClientStub
- Defined in:
- lib/telegram/bot/client_stub.rb
Overview
Stubbed client for tests. Saves all requests into #requests hash.
Defined Under Namespace
Modules: StubbedConstructor
Constant Summary
Constants inherited from Client
Telegram::Bot::Client::URL_TEMPLATE
Constants included from Async
Instance Attribute Summary collapse
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
Attributes inherited from Client
#base_uri, #client, #token, #username
Attributes included from Async
Attributes included from Botan::ClientHelpers
Class Method Summary collapse
-
.stub_all!(enabled = true) ⇒ Object
Any call to Client.new will return ClientStub instance when ‘enabled` is true.
- .stub_all? ⇒ Boolean
Instance Method Summary collapse
-
#initialize(token = nil, username = nil, **options) ⇒ ClientStub
constructor
A new instance of ClientStub.
- #request(action, body = {}) ⇒ Object
- #reset ⇒ Object
Methods inherited from Client
by_id, #http_request, #inspect, prepare_async_args, prepare_body, typed_response!
Methods included from Initializers
Methods included from DebugClient
Methods included from Async
#async, #async=, prepare_hash, prepended, thread_store
Constructor Details
#initialize(token = nil, username = nil, **options) ⇒ ClientStub
Returns a new instance of ClientStub.
37 38 39 40 |
# File 'lib/telegram/bot/client_stub.rb', line 37 def initialize(token = nil, username = nil, **) @username = username || [:username] || token reset end |
Instance Attribute Details
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
5 6 7 |
# File 'lib/telegram/bot/client_stub.rb', line 5 def requests @requests end |
Class Method Details
.stub_all!(enabled = true) ⇒ Object
Any call to Client.new will return ClientStub instance when ‘enabled` is true. Can be used with a block.
20 21 22 23 24 25 26 27 28 29 30 |
# 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? ⇒ Boolean
32 33 34 |
# File 'lib/telegram/bot/client_stub.rb', line 32 def stub_all? @_stub_all end |
Instance Method Details
#request(action, body = {}) ⇒ Object
46 47 48 |
# File 'lib/telegram/bot/client_stub.rb', line 46 def request(action, body = {}) requests[action.to_sym] << body end |
#reset ⇒ Object
42 43 44 |
# File 'lib/telegram/bot/client_stub.rb', line 42 def reset @requests = Hash.new { |h, k| h[k] = [] } end |