Class: Telegram::Bot::RSpec::ClientMatchers::MakeTelegramRequest

Inherits:
RSpec::Matchers::BuiltIn::BaseMatcher
  • Object
show all
Defined in:
lib/telegram/bot/rspec/client_matchers.rb

Constant Summary collapse

EXPECTATION_TYPES =
{
  exactly: :==,
  at_most: :>=,
  at_least: :<=,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionObject (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_requestsObject (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_messageObject



102
103
104
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 102

def failure_message
  "expected to #{base_message}"
end

#failure_message_when_negatedObject



106
107
108
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 106

def failure_message_when_negated
  "expected not to #{base_message}"
end

#matches?(proc) ⇒ Boolean

rubocop:disable Metrics/AbcSize

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


110
111
112
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 110

def supports_block_expectations?
  true
end

#timesObject



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