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::SERVER, Telegram::Bot::Client::URL_TEMPLATE
Constants included from Telegram::Bot::Client::ApiHelper
Telegram::Bot::Client::ApiHelper::METHODS_LIST_FILE
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
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
rubocop:disable Lint/MissingSuper.
- #request(action, body = {}) ⇒ Object
- #reset ⇒ Object
Methods inherited from Client
by_id, error_for_response, #http_request, #inspect, prepare_async_args, typed_response!, wrap
Methods included from Telegram::Bot::Client::ApiHelper
Methods included from DebugClient
Methods included from Async
#async, #async=, prepare_hash, prepended, thread_store
Constructor Details
#initialize(token = nil, username = nil, **options) ⇒ ClientStub
rubocop:disable Lint/MissingSuper
39 40 41 42 43 |
# File 'lib/telegram/bot/client_stub.rb', line 39 def initialize(token = nil, username = nil, **) # rubocop:disable Lint/MissingSuper @token = token || [:token] @username = username || [:username] || token reset end |
Instance Attribute Details
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
7 8 9 |
# File 'lib/telegram/bot/client_stub.rb', line 7 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.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/telegram/bot/client_stub.rb', line 22 def stub_all!(enabled = true) # rubocop:disable Style/OptionalBooleanParameter 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
34 35 36 |
# File 'lib/telegram/bot/client_stub.rb', line 34 def stub_all? @_stub_all end |
Instance Method Details
#request(action, body = {}) ⇒ Object
49 50 51 |
# File 'lib/telegram/bot/client_stub.rb', line 49 def request(action, body = {}) requests[action.to_sym] << body end |
#reset ⇒ Object
45 46 47 |
# File 'lib/telegram/bot/client_stub.rb', line 45 def reset @requests = Hash.new { |h, k| h[k] = [] } end |