Class: Telegram::Bot::RSpec::ClientMatchers::MakeTelegramRequest
- Inherits:
-
RSpec::Matchers::BuiltIn::BaseMatcher
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- Telegram::Bot::RSpec::ClientMatchers::MakeTelegramRequest
- Defined in:
- lib/telegram/bot/rspec/client_matchers.rb
Constant Summary collapse
- EXPECTATION_TYPES =
{ exactly: :==, at_most: :>=, at_least: :<=, }.freeze
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#performed_requests ⇒ Object
readonly
Returns the value of attribute performed_requests.
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(bot, action, description: nil) ⇒ MakeTelegramRequest
constructor
rubocop:disable Lint/MissingSuper.
-
#matches?(proc) ⇒ Boolean
rubocop:disable Metrics/AbcSize.
- #supports_block_expectations? ⇒ Boolean
- #times ⇒ Object
- #with(*args, &block) ⇒ Object
Constructor Details
#initialize(bot, action, description: nil) ⇒ MakeTelegramRequest
rubocop:disable Lint/MissingSuper
66 67 68 69 70 71 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 66 def initialize(bot, action, description: nil) # rubocop:disable Lint/MissingSuper @bot = bot @action = action @description = description || "make #{action} telegram request" exactly(1) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
64 65 66 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 64 def description @description end |
#performed_requests ⇒ Object (readonly)
Returns the value of attribute performed_requests.
64 65 66 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 64 def performed_requests @performed_requests end |
Instance Method Details
#failure_message ⇒ Object
102 103 104 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 102 def "expected to #{}" end |
#failure_message_when_negated ⇒ Object
106 107 108 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 106 def "expected not to #{}" end |
#matches?(proc) ⇒ Boolean
rubocop:disable Metrics/AbcSize
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 73 def matches?(proc) # rubocop:disable Metrics/AbcSize raise ArgumentError, 'matcher only supports block expectations' unless proc.is_a?(Proc) original_requests_count = bot.requests[action].count proc.call @performed_requests = bot.requests[action].drop(original_requests_count) @matching_requests_count = performed_requests.count do |request| !arg_list_matcher || arg_list_matcher.args_match?(request) end expectation_method = EXPECTATION_TYPES[expectation_type] expected_number.public_send(expectation_method, matching_requests_count) end |
#supports_block_expectations? ⇒ Boolean
110 111 112 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 110 def supports_block_expectations? true end |
#times ⇒ Object
98 99 100 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 98 def times self end |
#with(*args, &block) ⇒ Object
85 86 87 88 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 85 def with(*args, &block) @arg_list_matcher = ArgListMatcher.new(*args, &block) self end |