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

Returns a new instance of MakeTelegramRequest.



64
65
66
67
68
69
# 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

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



62
63
64
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 62

def description
  @description
end

#performed_requestsObject (readonly)

Returns the value of attribute performed_requests.



62
63
64
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 62

def performed_requests
  @performed_requests
end

Instance Method Details

#failure_messageObject



100
101
102
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 100

def failure_message
  "expected to #{base_message}"
end

#failure_message_when_negatedObject



104
105
106
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 104

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

#matches?(proc) ⇒ Boolean

rubocop:disable AbcSize

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
80
81
# 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?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 108

def supports_block_expectations?
  true
end

#timesObject



96
97
98
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 96

def times
  self
end

#with(*args, &block) ⇒ Object



83
84
85
86
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 83

def with(*args, &block)
  @arg_list_matcher = ArgListMatcher.new(*args, &block)
  self
end