lib/telegram/bot/rspec/client_matchers.rb in telegram-bot-0.16.1 vs lib/telegram/bot/rspec/client_matchers.rb in telegram-bot-0.16.3

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Telegram module Bot module RSpec # Proxy that uses RSpec::Mocks::ArgListMatcher when it's available. # Otherwise just performs `#==` match. @@ -59,18 +61,18 @@ at_least: :<=, }.freeze attr_reader :performed_requests, :description - def initialize(bot, action, description: nil) + def initialize(bot, action, description: nil) # rubocop:disable Lint/MissingSuper @bot = bot @action = action @description = description || "make #{action} telegram request" exactly(1) end - def matches?(proc) # rubocop:disable AbcSize + 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| @@ -113,18 +115,18 @@ attr_reader :bot, :action, :expectation_type, :expected_number, :arg_list_matcher, :matching_requests_count 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 + msg = "make #{expectation_type.to_s.tr('_', ' ')} #{expected_number} " \ + "#{bot.inspect}.#{action} requests," + 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 + msg end end # Check that bot performed request to telegram API: #