class Telegram::Bot::RSpec::ClientMatchers::MakeTelegramRequest
Constants
- EXPECTATION_TYPES
Attributes
action[R]
arg_list_matcher[R]
bot[R]
description[R]
expectation_type[R]
expected_number[R]
matching_requests_count[R]
performed_requests[R]
Public Class Methods
new(bot, action, description: nil)
click to toggle source
# File lib/telegram/bot/rspec/client_matchers.rb, line 64 def initialize(bot, action, description: nil) @bot = bot @action = action @description = description || "make #{action} telegram request" exactly(1) end
Public Instance Methods
failure_message()
click to toggle source
# File lib/telegram/bot/rspec/client_matchers.rb, line 100 def failure_message "expected to #{base_message}" end
failure_message_when_negated()
click to toggle source
# File lib/telegram/bot/rspec/client_matchers.rb, line 104 def failure_message_when_negated "expected not to #{base_message}" end
matches?(proc)
click to toggle source
# File lib/telegram/bot/rspec/client_matchers.rb, line 71 def matches?(proc) # rubocop:disable 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?()
click to toggle source
# File lib/telegram/bot/rspec/client_matchers.rb, line 108 def supports_block_expectations? true end
times()
click to toggle source
# File lib/telegram/bot/rspec/client_matchers.rb, line 96 def times self end
with(*args, &block)
click to toggle source
# File lib/telegram/bot/rspec/client_matchers.rb, line 83 def with(*args, &block) @arg_list_matcher = ArgListMatcher.new(*args, &block) self end
Private Instance Methods
base_message()
click to toggle source
# File lib/telegram/bot/rspec/client_matchers.rb, line 117 def base_message "make #{expectation_type.to_s.tr('_', ' ')} #{expected_number} " \ "#{bot.inspect}.#{action} requests,".tap do |msg| msg << " with #{arg_list_matcher}," if arg_list_matcher msg << " but made #{matching_requests_count}" if performed_requests actual_args = performed_requests.map(&:inspect).join(', ') msg << ", and #{performed_requests.count} with #{actual_args}" end end end